#include<bits/stdc++.h>
using namespace std;
int t,a[10000];
bool cheak(int x){
if(x==2){
return false;
}
for(int i = 2;i*i < x;i++){
if(x%i==0){
return true;
}
}
return false;
}
int main(){
cin>>t;
for(int i = 0;i < t;i++){
cin>>a[i];
for(int j = 0;j < t;j++){
if(cheak(a[i]+j)){
cout<<j<<endl;
break;
}
}
}
return 0;
}