PALINDROME

All submissions for this problem are available.
A positive integer is said to be a palindrome with respect to base b, if its representation in base b reads the same from left to right as from right to left. Palindromes are formed as follows:
Given a number, reverse its digits and add the resulting number to the original number. If the result isn't a palindrome, repeat the process. For example, start with 87 base 10. Applying this process, we obtain:
87 + 78 = 165
165 + 561 = 726
726 + 627 = 1353
1353 + 3531 = 4884, a palindrome
Whether all numbers eventually become palindromes under this process is unproved, but all base 10 numbers less than 10,000 have been tested. Every one becomes a palindrome in a relatively small number of steps (of the 900 3digit numbers, 90 are palindromes to start with and 735 of the remainder take fewer than 5 reversals and additions to yield a palindrome). Except, that is, for 196. Although no proof exists that it will not produce a palindrome, this number has been carried through to produce a 2 milliondigit number without producing a palindrome.
Input
The first line of input file contains positive integer t – the amount of test cases. Next t lines contain a positive integer and its base. Bases will be in the range 10 – 36.
Output
Print the palindrome produced. If no palindrome is produced after 10 additions, print the word “none” and the last sum.
Constraints
 10 ≤ base ≤ 36
 1 ≤ t ≤ 10
Example
Input:
5 420, 13 46894, 10 NITUK, 35 CODEGURU, 36 PRODAYA, 35 Output:
444 NONE, 1317544822 NONE, L6SFFT6K TLRCSCRLT BH8888HB
Author:  tejas02 
Tags  tejas02 
Date Added:  16042014 
Time Limit:  5 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, PERL, FORT, WSPC, PRLG, LISP sbcl, LISP clisp, JS, PERL6, TEXT, PYP3 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 