#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
string op,s;
ll p,vis;
bool check(string s){
ll ans1 = 0,ans2 = 0;
ll flag = 0,t;
for(ll i = 0;i < s.size();i++){
if(s[i] >= '0' && s[i] <= '9' && vis == 0){//判断数字是否合法
t = 0;
ll j = i;
while(s[j] >= '0' && s[j] <= '9' && j < s.size()){
t = t * 10 + s[j] - '0';
j ++;
}
p ++;
// cout << t << " " << p << " " << j << endl;
vis = 1;
if(p <= 4){
if(t > 255 || t < 0) return false;
}
else if(p == 5){
if(t > 65535 || t < 0) return false;
}
}
if(s[i] == '.') ans1 ++,vis = 0;
else if(s[i] == ':') ans2 ++,vis = 0;
if(ans2 == 1 && ans1 != 3) return false;//如果:已经出现 而.不够 return false
if(s[i] == '0'){//前导0
if((s[i - 1] == '.' || s[i - 1] == ':') && (s[i + 1] == '.' || s[i + 1] == ':')) flag = 1;
if(s[i - 1] > '0' && s[i - 1] <= '9') flag = 1;
if(!flag) return false;
}
else if((s[i] == '.' || s[i] == ':')){
if(s[i + 1] == '.' || s[i + 1] == ':') return false;
}
else if(s[i] == '-') return false;
}
if(ans1 != 3 || ans2 != 1) return false;
if(p != 5) return false;
return true;
}
map<string,ll> mp;
int main(){
// cout << check("192.168.1.1:8080");
cin >> n;
for(ll i = 1;i <= n;i++){
cin >> op >> s;
p = 0;
vis = 0;
if(!check(s)){
cout << "ERR" << endl;
continue;
}
if(op == "Server"){
if(mp.find(s) != mp.end()){//找到 不可以建立
cout << "FAIL" << endl;
continue;
}
else{ // 没找到 可以建立
mp[s] = i;
cout << "OK" << endl;
continue;
}
}
else if(op == "Client"){
if(mp.find(s) != mp.end()){//找到 可以连接
cout << mp[s] << endl;
continue;
}
else{ //没找到 不可以连接
cout << "FAIL" << endl;
continue;
}
}
}
// cout << p << endl;
return 0;
}