// King's Phone.cpp #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define PI 3.1415926535897932626 #define EXIT exit(0); #define PAUSE system("pause"); #define DEBUG puts("Here is a BUG"); #define SYNC_CLOSE ios::sync_with_stdio(false); #define what_is(x) cout << #x << " is " << x << endl; #define CLEAR(name, init) memset(name, init, sizeof(name)); const double eps = 1e-8; const int MAXN = (int)1e9 + 5; using namespace std; void get_xy(int n, int& x, int& y) { n--; x = n / 3; y = n % 3; } bool solve(void) { int n; scanf("%d", &n); int s[10]; set uni; bool flag = true; for(int i = 0; i < n; i++) { scanf("%d", s + i); if (s[i] < 1 || s[i] > 9) flag = false; uni.insert(s[i]); } if (n < 4 || uni.size() != n || !flag) return false; bool vis[10] = {0}; int mp[20][20]; CLEAR(mp, -1); mp[1][3] = 2; mp[1][7] = 4; mp[1][9] = 5; mp[2][8] = 5; mp[3][7] = 5; mp[3][9] = 6; mp[4][6] = 5; mp[7][9] = 8; for(int i = 0; i < n-1; i++) { int a = s[i]; int b = s[i+1]; if (a > b) swap(a, b); if (mp[a][b] != -1) { int c = mp[a][b]; if (!vis[c]) return false; } vis[a] = true; vis[b] = true; } return true; } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("D:\\Documents\\Disk_Synchronous\\Programs\\Acm\\input.txt", "r", stdin); #endif int T; cin >> T; while(T--) { if (solve()) puts("valid"); else puts("invalid"); } return 0; }