P10985 [HackerEarth] p lover
普及
题目描述

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.

SAMPLE INPUT
3
42
108
250

SAMPLE OUTPUT
101
131
313

Explanation

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

输入格式

见题面

输出格式

见题面

样例输入
3 42 108 250 SAMPLE
样例输出
101 131 313