Circular Numbers

An (XY, D)—CIRCULAR NUMBER is a number whose last two digits are X and Y, and multiplication of the number by the single digit D is equivalent to moving the last two digits (XY) to the beginning of the number. For example, the number 132832080200501253 is a (53, 4)—CIRCULAR NUMBER because 132832080200501253 * 4 = 531328320802005012. Write a program that asks for two-digit number XY and a single digit D, and prints the SMALLEST (XY, D)—CIRCULAR NUMBER or prints a message NONE if none exists. It is guaranteed that your number will not exceed 255 digits.

INPUT

An integer number, N, indicating the total number of cases. On each of the next N lines are the two-digit number XY and the single digit D, separated by a space.

OUTPUT

The smallest circular number (if one exists with less than 255 digits) that satisfies the given condition; otherwise output the message NONE.

SAMPLE DATA

Input file

1
53 4

Output file

132832080200501253

All Submissions
Best Solutions


Point Value: 10
Time Limit: 2.00s
Memory Limit: 16M
Added: Feb 24, 2009

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

Please answer the comment below

is there any sources you can suggest me and any areas i should start thinking about? im totally stuck on this one