~cpp import unittest MAX_VALUE = 4294967295 MAX_COUNT = 1000 class ReverseAndAdd: def __init__(self): self.result = () def compute(self, n): count = 0 while n != int(str(n)[::-1]): n += int(str(n)[::-1]) count+= 1 if self.overBoundary(count, n): return -1, n if self.overBoundary(count, n): return -1, n return count, n def overBoundary(self, count, n): if count >= MAX_COUNT or n > MAX_VALUE: return True return False def printRepeatNum(self, num): for i in range(0,num*2,2): print self.result[i], self.result[i+1] class ReverseAndAddTestCase(unittest.TestCase): def test1(self): r = ReverseAndAdd() self.assertEquals((4,9339), r.compute(195)) self.assertEquals((5,45254), r.compute(265)) self.assertEquals((3,6666), r.compute(750)) self.assertEquals((0,111), r.compute(111)) def main(): r = ReverseAndAdd() num = input() for testcase in range(num): r.result += r.compute(input()) r.printRepeatNum(num) if __name__ == '__main__': #unittest.main() main()