CANTON - Count on Cantor

题意翻译

# 题目描述(重题请做P1014) 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的。他是用下面这一张表来证明这一命题的: ### $1/1,1/2,1/3,1/4,1/5...$ ### $2/1,2/2,2/3,2/4...$ ### $3/1,3/2,3/3...$ ### $4/1,4/2...$ ### $5/1...$ ### $...$ 我们以$Z$字形给上表的每一项编号。第一项是$1/1$,随后是$1/2,2/1,3/1,2/2...$ # 输入与输出 ## 输入 输入共$N+1$行。 第一行代表数的个数$N$。接下来$N$行,每一行代表一个数$a_i$。 ## 输出 对于每一个数,输出$TERM~ a_i~IS~x$($a_i$如上,$x$代表$Cantor$表的第$N$项)。 ### 范围: $1<=t<=20,1<=x<=10^7$

题目描述

One of the famous proofs of modern mathematics is Georg Cantor's demonstration that the set of rational numbers is enumerable. The proof works by using an explicit enumeration of rational numbers as shown in the diagram below. ``` 1/1 1/2 1/3 1/4 1/5 ... 2/1 2/2 2/3 2/4 3/1 3/2 3/3 4/1 4/2 5/1 ``` In the above diagram, the first term is 1/1, the second term is 1/2, the third term is 2/1, the fourth term is 3/1, the fifth term is 2/2, and so on.

输入输出格式

输入格式


The input starts with a line containing a single integer **t** <= 20, the number of test cases. **t** test cases follow. Then, it contains a single number per line.

输出格式


You are to write a program that will read a list of numbers in the range from 1 to 10^7 and will print for each number the corresponding term in Cantor's enumeration as given below.

输入输出样例

输入样例 #1

3
3
14
7

输出样例 #1

TERM 3 IS 2/1
TERM 14 IS 2/4
TERM 7 IS 1/4