#include<bits/stdc++.h>
using namespace std;
int n;
string op[100],ad[100];
bool check(string s){
int l=s.size(),dian=0,maohao=0,abcde=0;
long long tmp=0;
for(int i=0;i<l;i++){
if((i==0 || (s[i-1]=='.'||s[i-1]==':')) && s[i]>='0' && s[i]<='9') abcde++;
if(s[i]=='.'||s[i]==':'){
if(s[i]=='.') dian++;
else if(s[i]==':') maohao++;
if(dian<3 && maohao) return false;
if(abcde==0) return false;
if(0<=tmp && tmp<=255){
tmp=0;
continue;
}
else return false;
}
else if(s[i]<'0'||s[i]>'9') return false;
if(i && tmp==0 && s[i-1]=='0') return false;
tmp=tmp*10+s[i]-'0';
}
if(dian!=3 || maohao!=1 || abcde!=5) return false;
if(0<=tmp && tmp<=65535) return true;
else return false;
}
int find(int i){
int j=1;
for(j=1;j<i;j++){
if(ad[j]==ad[i]) return j;
}
return -1;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>op[i]>>ad[i];
for(int i=1;i<=n;i++){
if(!check(ad[i])) cout<<"ERR"<<endl;
else if(op[i]=="Server"){
if(find(i)==-1) cout<<"OK"<<endl;
else cout<<"FAIL"<<endl;
}
else if(op[i]=="Client"){
int f=find(i);
if(f!=-1) cout<<f<<endl;
else cout<<"FAIL"<<endl;
}
}
return 0;
}