#include #include using namespace std; int number[10]; int k; int Type(int a){ if (a % 2 == 1&&a!=5) return -1; else if (a==5) return 0; else if (a == 4 || a == 6) return 1; else return 2; } int main(){ int T, i,j; bool flag; bool W[10]; cin >> T; while (T--){ memset(W, 0, sizeof(W)); flag = 1; cin >> k; if (k) for (i = 0; i < k; i++){ cin >> number[i]; if (number[i]>9||number[i]==0) flag = 0; for (j = 0; j < i; j++){ if (number[i] == number[j]) flag = 0; } } if (k<4||!flag) flag = 0; else{ for (i = 0; i < k-1; i++){ if (Type(number[i]) == Type(number[i + 1]) && !W[(number[i] + number[i + 1])/ 2]){ flag = 0; break; } else W[number[i]] = 1; } } if (flag) cout << "valid" << endl; else cout << "invalid" << endl; } return 0; }