#include<bits/stdc++.h>
#define ll long long
using namespace std;
map < string,int > a;
void put(){
printf("ERR\n");
}
int main(){
ios::sync_with_stdio(false);
int n;
string op,ad;
cin >> n;
for(int sum = 1; sum <= n; ++sum){
cin >> op >> ad;
bool flag=0;
int len = ad.size(),now = 0,m = 0;
for(int i = 0;i < ad.size(); ++i){
if(ad[i] >= '0' && ad[i] <= '9') now = now*10+ad[i]-'0';
else if(ad[i] == '.'){
if(m<3){
if(now >= 0 && now <= 255) ++m, now = 0;
else{put(); flag=1; break;}
}
else{put(); flag=1; break;}
}
else if(ad[i]==':' && m == 3){
if(now >= 0 && now <= 255) ++m, now = 0;
else{put(); flag=1; break;}
}
else{put(); flag=1; break;}
if(ad[i] == '0' && now == 0){
if(ad[i+1] >= '0' && ad[i+1] <= '9'){put(); flag=1; break;}
}
}
if(flag) continue;
if(now > 65535){put(); continue;}
if(op == "Server"){
if(a[ad] > 0 && a[ad] <= n) printf("FAIL\n");
else{a[ad] = sum; printf("OK\n");}
}
else{
if(a[ad] > 0 && a[ad] <= n) cout<<a[ad]<<endl;
else cout<<"FAIL\n";
}
}
return 0;
}