#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
const int maxn=1e4+5;
int main()
{
int t,n;
cin>>t;
while(t--)
{
scanf("%d",&n);
int m=n/3;
int k=n%3;
printf("%d\n",(m*2+k)%3);
}
return 0;
}