#include<bits/stdc++.h>
#define int long long
using namespace std;
map<string,int>mp;
int n,cnt=0;
inline bool pd(string ip){//判断是否合法
string s[11]={};
char c[11]={};
//进行区分
int count1=1,count2=1;
for(int i=0;i<ip.size();i++){
//数字
if(ip[i]>='0'&&ip[i]<='9'){
s[count1]+=ip[i];
}
//字符
else{
++count1;
c[count2++]=ip[i];
}
}
//判断四个字符
for(int i=1;i<=3;i++){
if(c[i]!='.')return 0;
}
if(c[4]!=':')return 0;
//判断前导零
for(int i=1;i<=5;i++){
if(s[i][0] == '0' && s[i].size() > 1)return 0;
}
//判断是否越界
int a1=stoi(s[1]),b1=stoi(s[2]),c1=stoi(s[3]),d1=stoi(s[4]),e1=stoi(s[5]);
if(a1>255 || b1>255 || c1>255 || d1>255 || e1>65535 || a1<0 || b1<0 || c1<0 || d1<0 || e1<0){
return 0;
}
return 1;
}
signed main(){
cin>>n;
while(n--){
string type,IP;//类型 and IP
cin>>type>>IP;
++cnt;
if(pd(IP)){
if(type=="Server"){//服务鸡
bool b=1;
for(int i=1;i<=cnt;i++){
if(mp[IP]){//判断是否已被注册
cout<<"FAIL\n";
b=0;
break;
}
}
if(b){//加入
mp[IP]=cnt;
cout<<"OK\n";
}
}
if(type=="Client"){//客户鸡
if(mp[IP]){
cout<<mp[IP]<<'\n';
}
else cout<<"FAIL\n";
}
}
else{//有大问题
cout<<"ERR\n";
}
}
}
/*
5
Server 192.168.1.1:8080
Server 192.168.1.1:8080
Client 192.168.1.1:8080
Client 192.168.1.1:80
Client 192.168.1.1:99999
*/
编译器加入指令:-std=c++14 -O2 -Wall -lm