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