#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool isspecial(char x) {
for (char c: "!@#$%^&*()") {
if (c == x) {
return true;
}
}
return false;
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
bool valid = true;
bool lower = false;
bool upper = false;
bool digit = false;
bool special = false;
for (char c: s) {
lower |= islower(c);
upper |= isupper(c);
digit |= isdigit(c);
special |= isspecial(c);
}
valid = lower & upper & digit & special;
puts(valid ? "valid": "invalid");
}
}