P's lover

3.9

14 votes
Problem

A:It is a natural number greater than 1 that has no positive divisors other than 1 and itself.

B: It is a number that remains the same when its digits are reversed. It is "symmetrical".

Patrik lives in Palestine. He loves everything starting with P and so numbers also. His friend gave him a number X and asked him to find smallest integer say Y where, Y ≥ X such that Y is a A and B type number. You task is to Help Patrik to find required number Y every time.

Input format:
First line of input contains an integer t, which is the number of test cases. t lines follow, with each test containing an integer X.

Output format:
For each test case output a single line number Y which is of type A and B both.

Constraints:
1<= X <= 1000000

1<=t<=100

NOTE: A and B are a type of number. Read definition statement properly if you are not getting.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

101 is the smallest number prime number which is palindrome also after 42. Similarly all the cases have respective output on provided input.

Editor Image

?