#C6206. Smallest Prime Palindrome

    ID: 49941 Type: Default 1000ms 256MiB

Smallest Prime Palindrome

Smallest Prime Palindrome

You are given an integer N and your task is to find the smallest prime palindrome greater than or equal to N. A prime palindrome is defined as a number that is both prime and a palindrome. In mathematical terms, for a number p to be considered a prime palindrome, it must satisfy:

\(\text{isPrime}(p)=\text{true}\quad \text{and} \quad p = \text{reverse}(p)\)

Your program should read multiple test cases and for each test case output the required number.

inputFormat

The input is given via stdin and consists of:

  • The first line contains an integer T representing the number of test cases.
  • The following T lines each contain a single integer N.

outputFormat

For each test case, output via stdout a single line containing the smallest prime palindrome greater than or equal to the given integer N.

## sample
3
31
130
777
101

131 787

</p>