/* *********************************************** Author :kuangbin Created Time :2016/3/12 19:12:59 File Name :F:\ACM\2016ACM\BestCoder\BC75\B.cpp ************************************************ */ #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int vis[3][3]; bool check(int a[],int n) { if(n < 4)return false; for(int i = 0;i < n;i++) if(a[i] <= 0 || a[i] > 9) return false; memset(vis,false,sizeof(vis)); int x = (a[0]-1)/3; int y = (a[0]-1)%3; vis[x][y] = true; int px = x; int py = y; for(int i = 1;i < n;i++) { x = (a[i]-1)/3; y = (a[i]-1)%3; if(vis[x][y])return false; vis[x][y] = true; if (x == px) { if (abs(y-py) == 2 && !vis[x][(y+py)/2]) return false; } else if (y == py) { if (abs(x-px) == 2 && !vis[(x+px)/2][y]) return false; } else if (abs(x-px) == 2 && abs(y-py) == 2 && !vis[1][1]) { return false; } px = x; py = y; } return true; } int a[100]; int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int T; int n; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i = 0;i < n;i++) scanf("%d",&a[i]); if (check(a,n))puts("valid"); else puts("invalid"); } return 0; }