#include #include #include #define FOR(a,b,c) for(int a=b;a<=c;a++) #define LL long long using namespace std; bool b[10]; int T, n, a[1000]; int main(){ scanf("%d", &T); while (T--){ scanf("%d", &n); bool flag = 1; memset(b, 0, sizeof(b)); FOR(i, 1, n) scanf("%d", &a[i]); if (n < 4){ printf("invalid\n"); continue; } b[a[1]] = 1; if (a[1] < 1 || a[1] > 9){ printf("invalid\n"); continue; } FOR(i, 2, n){ if ((((a[i - 1] == 1) && (a[i] == 3) || (a[i - 1] == 3) && a[i] == 1) && (!b[2])) || (((a[i - 1] == 1) && (a[i] == 7) || (a[i - 1] == 7) && a[i] == 1) && (!b[4])) || (((a[i - 1] == 3) && (a[i] == 9) || (a[i - 1] == 9) && a[i] == 3) && (!b[6])) || (((a[i - 1] == 9) && (a[i] == 7) || (a[i - 1] == 7) && a[i] == 9) && (!b[8])) || (((a[i - 1] == 4) && (a[i] == 6) || (a[i - 1] == 6) && a[i] == 4) && (!b[5])) || (((a[i - 1] == 2) && (a[i] == 8) || (a[i - 1] == 8) && a[i] == 2) && (!b[5])) || (((a[i - 1] == 1) && (a[i] == 9) || (a[i - 1] == 9) && a[i] == 1) && (!b[5])) || (((a[i - 1] == 3) && (a[i] == 7) || (a[i - 1] == 7) && a[i] == 3) && (!b[5]))) { flag = 0; break; } if (a[i] < 1 || a[i] > 9){ flag = 0; break; } if (b[a[i]]){ flag = 0; break; } b[a[i]] = 1; } if (flag) printf("valid\n"); else printf("invalid\n"); } return 0; }