#include <cstdio>
#include <iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<stack>
using namespace std;
int n,m,t;
int i,j;
bool cmp(const char a,const char b){
return a<b;
}
int main()
{
scanf("%d",&t);
while(t--){
m=0;
scanf("%d",&n);
for(i=1;i<=n;++i){
int k=i%3;
if(i%3==1||i%3==0)
{
m+=k;
//cout<<m<<endl;
}
else
{
m+=1;
}
}
printf("%d\n",m%3);
}
return 0;
}