#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'
using namespace std;
const int N = 2e5 + 5;
int tc, n, m, a[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); // cout.tie(0);
string specialCharacters = "[!@#$%^&*()]";
cin >> tc;
while (tc--) {
string password;
cin >> password;
bool validLength = true;
if (password.size() < 8) {
validLength = false;
}
bool hasSpecialCharacter = false, hasUppercase = false, hasLowercase = false, hasDigit = false;
for (int i = 0; i < password.size(); i++) {
if (specialCharacters.find(password[i]) != string::npos) {
hasSpecialCharacter = true;
}
if (isupper(password[i])) {
hasUppercase = true;
}
if (islower(password[i])) {
hasLowercase = true;
}
if (isdigit(password[i])) {
hasDigit = true;
}
}
bool isValid = validLength && hasSpecialCharacter && hasUppercase && hasLowercase && hasDigit;
cout << (isValid ? "valid" : "invalid") << endl;
}
return 0;
}