#include // #include using namespace std; // using namespace atcoder; using lint = long long; long const mod = 1e9+7; //long const mod = 998244353; vectorpp; void solve(){ lint a,p; scanf("%lld %lld", &a, &p); if(!binary_search(pp.begin(),pp.end(), p)){ cout << -1 << endl; return; } if(a%p==0){ printf("%d\n",0); return; }else{ printf("%d\n",1); } } int main(){ pp.push_back(2); for(int i=3;i<=5000000;i+= 2){ bool chk = true; for(int j = 0;j < pp.size(); j++){ if(pp[j] > sqrt(i))break; if(i % pp[j] == 0){ chk = false; break; } } if(chk)pp.push_back(i); } lint t; scanf("%lld", &t); for(int i=0;i