#include<bits/stdc++.h>
using namespace std;
/// .................... type def
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll N = 1e5+5;
int prime[N];
void seive(ll n){
n+=2;
int sqn = sqrt(n)+1;
for(int i=4;i<=n;i+=2) prime[i]=1;
for(int i=3;i<=sqn;i+=2){
if(prime[i]==1) continue;
for(int j=i+i;j<=n;j+=i) prime[j]=1;
}
}
int popcount(ll x)
{
int cnt=0;
for(int i=0;i<64;i++) if((x&(1ull<<i))!=0) ++cnt; return cnt;
}
void solve()
{
string s; cin>>s;
int n=s.size();
if(n<8) {cout<<"invalid"<<endl; return;}
bool lower=false,upper=false,digit=false,special=false;
for(auto &x:s)
{
lower |=(x>='a' && x<='z');
upper |=(x>='A' && x<='Z');
digit |=(x<='9' && x>='0');
special |=(x=='[' || x==']' || x=='!' || x=='@' || x=='#' || x=='$' || x=='%' || x=='^' || x=='&' || x=='*' || x=='(' || x==')');
}
if(lower && upper && digit && special) cout<<"valid"<<endl;
else cout<<"invalid"<<endl;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t; cin>>t; while(t--) solve();
}