#include<iostream>
#include<map>
#include<cstring>
using namespace std;
map<string,int> ma;
int n;
bool check(string s) {
int cnt1=0,cnt2=0;
for(int i=0; i<s.size(); i++) {
if(!((s[i] >= '0' && s[i] <= '9') || s[i] == '.' || s[i] == ':')) {
return false;
}
if(s[i]=='.') cnt1++;
if(s[i]==':') {
if(cnt1!=3) return false;
else cnt2++;
}
}
if(cnt1!=3||cnt2!=1) return false;
bool flg=false;
int res=0;
for(int i=0; i<s.size(); i++) {
if(s[i]=='.'||s[i]==':') {
if(flg==false&&res==0) return false;
if(res<0||res>255) return false;
res=0;
flg=false;
}
if(s[i]>='0'&&s[i]<='9') {
if(flg==true) return false;
res *= 10;
res += s[i] - '0';
}
if(s[i]=='0'&&res==0) {
if(flg==false) flg=true;
else return false;
}
}
if(flg==false&&res==0) return false;
if(res<0||res>65535) return false;
return true;
}
int main() {
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=1; i<=n; i++) {
string op,str;
cin>>op;
cin>>str;
if(op=="Server") {
bool vis=check(str);
if(vis==true) {
if(ma.find(str)==ma.end()) {
cout<<"OK"<<endl;
ma[str]=i;
} else {
cout<<"FAIL"<<endl;
}
} else {
cout<<"ERR"<<endl;
}
} else if(op=="Client") {
bool vis=check(str);
if(vis==true) {
if(ma.find(str)==ma.end()) {
cout<<"FAIL"<<endl;
} else {
cout<<ma[str]<<endl;
}
} else {
cout<<"ERR"<<endl;
}
}
}
return 0;
}