#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef pair pii; typedef long long ull; typedef long long ll; typedef vector vi; #define xx first #define yy second #define rep(i, a, n) for (int i = a; i < n; i++) #define sa(n) scanf("%d", &(n)) #define vep(c) for(decltype((c).begin()) it = (c).begin(); it != (c).end(); it++) const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e5 + 12; int a[10], n, list[10]; bool judge(int s, int e) { list[s] = 1; if (s > e) swap(s, e); if (s == 1 && e == 3 && !list[2]) return false; if (s == 1 && e == 7 && !list[4]) return false; if (s == 1 && e == 9 && !list[5]) return false; if (s == 3 && e == 7 && !list[5]) return false; if (s == 3 && e == 9 && !list[6]) return false; if (s == 7 && e == 9 && !list[8]) return false; if (s == 2 && e == 8 && !list[5]) return false; if (s == 4 && e == 6 && !list[5]) return false; return true; } int main(void) { int T; cin >> T; while (T--) { sa(n); bool ok = true; memset(list, 0, sizeof(list)); rep (i, 0, n) { sa(a[i]); if (a[i] < 1 || a[i] > 9) { ok = false; continue; } if (list[a[i]]) ok = false; list[a[i]] = 1; } if (n < 4 || !ok) { cout << "invalid" << endl; continue; } memset(list, 0, sizeof(list)); rep (i, 0, n - 1) { if (!judge(a[i], a[i + 1])) { ok = false; break; } } if (n < 4 || !ok) { cout << "invalid" << endl; continue; } cout << "valid" << endl; } return 0; }