10805 - Thousands Separator   

Description

Consider an input string of  numeric characters, e.g.,
      1234567895793

Your task is to add thousands separators so that the output would look like
      1,234,567,895,793

If the input string contains non-numeric characters, e.g.,
     123q5
then you just need to print
     NaN

Input

The first line is an integer N(<=1000) indicating the number of test cases.
Each of the next N lines is a string that needs to be printed with thousands separators.

case 1 : 0 < len(string) <= 10, all characters are number
case 2 : 0 < len(string) <= 100, all characters are number
case 3 : 0 < len(string) <= 100000
case 4 : 0 < len(string) <= 100000

Output

The output contains N lines showing  the results of the N test cases.
Each line is ended with a newline character.
If the test case is a valid numeric string, then print that number with thousands separators; otherwise,  print NaN.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss