#include #include #include #include #include #include #include using namespace std; int mid[10][10]; bool have[10]; void addMid(int a, int b, int c) { mid[a][c] = b; mid[c][a] = b; } int MAIN() { memset(mid, 0, sizeof(mid)); addMid(1,2,3); addMid(4,5,6); addMid(7,8,9); addMid(1,4,7); addMid(2,5,8); addMid(3,6,9); addMid(1,5,9); addMid(3,5,7); int T; scanf("%d", &T); while(T--) { bool bad = false; int len; scanf("%d", &len); if(len < 4) bad = true; int num; memset(have, false, sizeof(have)); int prev = 0; for(int i = 1; i <= len; i++) { scanf("%d", &num); if(num <= 0 || num > 9) bad = true; else { if(have[num]) { bad = true; } have[num] = true; if(mid[num][prev] > 0 && !have[mid[num][prev]]) { bad = true; } prev = num; } } if(bad) printf("invalid\n"); else printf("valid\n"); } return 0; } int main() { #ifdef LOCAL_TEST freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif //ios :: sync_with_stdio(false); //cout << fixed << setprecision(16); int ret = MAIN(); return ret; }