#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int pingfangc(int n){
int i,m;
m=(n%3)*(n%3)%3;
int h[14]={1,0,0,1,1,1,0,0,0,1,0,0,0,0};
for(i=2;i<14;i++){
m=(m*m)%3;
if(h[i]==1){
m=(m*n)%3;
}
}
return m;
}
int main()
{
int n,T,i;
int sum;
scanf("%d",&T);
while(T--){
sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
sum=(sum+pingfangc(i))%3;
}
printf("%d\n",sum);
}
}