import sys
sys.stdin = open("input.txt", "r")
def reverse(x):
res = 0
while x > 0:
t = x % 10
res = res * 10 + t
x = x // 10
return res
def isPrime(x):
if x == 1:
return False
for i in range(2, x//2 +1):
if x % i == 0:
return False
return True
n = int(input())
a = list(map(int,input().split()))
for i in a:
now = reverse(i)
if isPrime(now):
print(now, end=" ")
reverse 함수는 해당 끝자리부터 돌면서 자릿수를 올려가며진행해준다.
isPrime 함수는 해당 수를 끝까지 확인하지 않고 반까지만 확인해주면 된다. (배수는 전부 소수가 아니니까 그 절반 부까지 확인 해주면 된다.)