#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
bool prime_poo(long long prime){
if (prime <= 1)return false;
for (long long p = 2; p < prime; p++){
if (prime % p == 0){
return false;
}
}
return true;
}
signed main(){
ios::sync_with_stdio(false);
long long n, a[N];
string s;
cin >> n;
for (long long i = 0; i < n; i++){
cin >> a[i];
long long b = a[i];
while(b > 0){
if (prime_poo(b) == false){
break;
}
else if (b/10 == 0){
cout << a;
if (i+1 != n){
cout << endl;
}
break;
}
else {
b/=10;
}
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMWU2OwoKYm9vbCBwcmltZV9wb28obG9uZyBsb25nIHByaW1lKXsKICAgIGlmIChwcmltZSA8PSAxKXJldHVybiBmYWxzZTsKICAgIGZvciAobG9uZyBsb25nIHAgPSAyOyBwIDwgcHJpbWU7IHArKyl7CiAgICAgICAgaWYgKHByaW1lICUgcCA9PSAwKXsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiB0cnVlOwp9CgpzaWduZWQgbWFpbigpewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwoKICAgIGxvbmcgbG9uZyBuLCBhW05dOwogICAgc3RyaW5nIHM7CiAgICBjaW4gPj4gbjsKICAgIGZvciAobG9uZyBsb25nIGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgICAgICBsb25nIGxvbmcgYiA9IGFbaV07CiAgICAgICAgd2hpbGUoYiA+IDApewogICAgICAgICAgICBpZiAocHJpbWVfcG9vKGIpID09IGZhbHNlKXsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYgKGIvMTAgPT0gMCl7CiAgICAgICAgICAgICAgICBjb3V0IDw8IGE7CiAgICAgICAgICAgICAgICBpZiAoaSsxICE9IG4pewogICAgICAgICAgICAgICAgICAgIGNvdXQgPDwgZW5kbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgICAgIGIvPTEwOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9Cg==