#include<iostream>
#include<cmath>
#include<cstring>
#include<stack>
#include<set>
#include<algorithm>
#include<map>
#include<cstdlib>
using namespace std;
int main()
{
long long t;
long long n;
scanf("%d",&t);
while(t--)
{
double ans=1;
int flag=0;
long long sum=0;
scanf("%d",&n);
for(long long i=1;i<=n;i++)
{
if(i%3==0)
sum+=0;
if(i%3==2||i%3==1)
sum+=1;
}
printf("%lld\n",sum%3);
}
}