#include #define NMAX 10000 int st[2][NMAX+10]; /* 1, 2, 3 e evident si 4, 5, 6 e A, B, C */ int main(void) { int t,l,v,i; int niv[2]; int valid[2]; freopen("perle.in","r",stdin); freopen("perle.out","w",stdout); scanf("%d",&t); while (t--) { scanf("%d",&l); if (l == 1) {scanf("%d",&v); printf("1\n"); continue; } else { valid[1] = valid[0] = 1; niv[1] = niv[0] = 1; st[0][0] = 5; st[1][0] = 6; while (l--) { scanf("%d",&v); for (i = 0; i < 2; i++) /* trist da doar 2 valori vreau */ { if (valid[i]) { if (st[i][niv[i]-1] < 4) { valid[i] = (st[i][--niv[i]]==v); continue; } if (st[i][niv[i]-1] == 4) { niv[i]--; continue; } if (st[i][niv[i]-1]==5) { if (v == 3) valid[i] = 0; if (v == 1) { niv[i]--; st[i][niv[i]++] = 6; st[i][niv[i]++] = 4; st[i][niv[i]++] = 3; st[i][niv[i]++] = 4; } /* 2-ul e ok :D */ continue; } /* e C in stiva */ if (v == 2) niv[i]--; if (v == 1) { niv[i]--; st[i][niv[i]++] = 4; st[i][niv[i]++] = 2; } if (v == 3) { niv[i]--; st[i][niv[i]++] = 6; st[i][niv[i]++] = 5; } } if (!niv[i] && l) valid[i] = 0; } } printf("%d\n",((!niv[0] && valid[0]) || (!niv[1] && valid[1]))); } } return 0; }