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