#include<bits/stdc++.h>
using namespace std;
bool ok(string t){
vector<string>v;
string s;
t.push_back('-');
long long c1 = 0, c2 = 0;
for(long long i=0; i<t.size(); i++){
if(t[i]=='.' || t[i]==':' || t[i]=='-'){
if(t[i] == '.')c1++;
if(t[i] == ':')c2++;
if(!s.empty()) v.push_back(s);
s.clear();
}else s+=t[i];
}
if(c1!=3 || c2 != 1)return 0;
if(v.size() != 5)return 0;
for(long long i=0; i<4; i++){
string w = v[i];
if(w.size() != 1 && w[0] == '0')return 0;
int x = stoll(v[i]);
if(x<0 || x>255)return 0;
}
string w = v[4];
if(w.size() != 1 && w[0] == '0')return 0;
int x = stoll(w);
if(x<0 || x>65535)return 0;
return 1;
}
int main(){
long long n;
map<string,long long>se;
cin>>n;
for(long long i=1;i<=n;i++){
string s,s2;
cin>>s>>s2;
if(ok(s2)){
if(s=="Server"){
if(se.count(s2)){
cout<<"FAIL"<<endl;
}
else{
se[s2]=i;
cout<<"OK"<<endl;
}
}
else{
if(se.count(s2)) cout<<se[s2]<<endl;
else cout<<"FAIL"<<endl;
}
}
else{
cout<<"ERR"<<endl;
}
}
}