#include "iostream" #include "cstdio" #include "cstring" #include "algorithm" #include "queue" #include "stack" #include "cmath" #include "utility" #include "map" #include "set" #include "vector" #include "list" #include "string" #include "cstdlib" using namespace std; typedef long long ll; #define X first #define Y second #define exp 1e-8 const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const int MAXN = 10; int t, n, a[MAXN], cnt[MAXN]; std::map mp; int main(int argc, char const *argv[]) { scanf("%d", &t); while(t--) { mp.clear(); bool flag = false; scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%d", &a[i]); if(a[i] == 0 || a[i] > 9) flag = true; } if(flag || n < 4) { printf("invalid\n"); continue; } for(int i = 0; i < n; ++i) mp[a[i]] = i; memset(cnt, 0, sizeof(cnt)); for(int i = 0; i < n; ++i) cnt[a[i]]++; for(int i = 0; i < n; ++i) if(cnt[a[i]] > 1) { flag = true; break; } if(flag) { printf("invalid\n"); continue; } for(int i = 0; i < n - 1; ++i) if((a[i] == 1 && a[i + 1] == 3 && (mp[2] > i + 1 || !cnt[2])) || (a[i] == 1 && a[i + 1] == 7 && (mp[4] > i + 1 || !cnt[4])) || (a[i] == 1 && a[i + 1] == 9 && (mp[5] > i + 1 || !cnt[5])) || (a[i] == 2 && a[i + 1] == 8 && (mp[5] > i + 1 || !cnt[5])) || (a[i] == 3 && a[i + 1] == 1 && (mp[2] > i + 1 || !cnt[2])) || (a[i] == 3 && a[i + 1] == 7 && (mp[5] > i + 1 || !cnt[5])) || (a[i] == 3 && a[i + 1] == 9 && (mp[6] > i + 1 || !cnt[6])) || (a[i] == 4 && a[i + 1] == 6 && (mp[5] > i + 1 || !cnt[5])) || (a[i] == 6 && a[i + 1] == 4 && (mp[5] > i + 1 || !cnt[5])) || (a[i] == 7 && a[i + 1] == 1 && (mp[4] > i + 1 || !cnt[4])) || (a[i] == 7 && a[i + 1] == 3 && (mp[5] > i + 1 || !cnt[5])) || (a[i] == 7 && a[i + 1] == 9 && (mp[8] > i + 1 || !cnt[8])) || (a[i] == 8 && a[i + 1] == 2 && (mp[5] > i + 1 || !cnt[5])) || (a[i] == 9 && a[i + 1] == 1 && (mp[5] > i + 1 || !cnt[5])) || (a[i] == 9 && a[i + 1] == 3 && (mp[6] > i + 1 || !cnt[6])) || (a[i] == 9 && a[i + 1] == 7 && (mp[8] > i + 1 || !cnt[8]))) { flag = true; break; } if(flag) { printf("invalid\n"); continue; } printf("valid\n"); } return 0; }