#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int z,y,i,sum;
z=n/3;
y=n%3;
if(y==1)
{
sum=z*2+1;
}
else if(y==2)
sum=z*2+2;
else
sum=z*2;
printf("%d\n",sum%3);
}
return 0;
}