#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define up(i,j,k,l) for(int i=j;i<=k;i+=l)
#define down(i,j,k,l) for(int i=j;i>=k;i-=l)
using namespace std;
int n;
string s1,s2;
map<string,int> mp;
int ct;
bool checks2()
{
int res=0,ct=0,ctm=0;
up(i,0,(int)s2.length()-1,1){
if(s2[i]=='-'){
return false;
}
if(s2[i]=='.' || s2[i]==':'){
if(res>256){
return false;
}
if(s2[i]==':'){
ctm=1;
if(ct!=3){
return false;
}
}
if(s2[i]=='.' || s2[i]==':'){
if(i+2<=(int)s2.length()-1 && s2[i+1]=='0' && s2[i+2]>='0' && s2[i+2]<='9'){
return false;
}
ct++;
}
res=0;
}
else{
res*=10;
res+=(int)s2[i]-'0';
}
}
if(res>65535 || ctm==0){
return false;
}
else{
return true;
}
}
void solve()
{
cin>>n;
up(i,1,n,1){
ct=i;
cin>>s1>>s2;
if(checks2()==false){
cout<<"ERR";
}
else{
if(s1=="Server"){
if(!mp.count(s2)){
mp[s2]=ct;
cout<<"OK";
}
else{
cout<<"FAIL";
}
}
else{
if(mp.count(s2)){
cout<<mp[s2];
}
else{
cout<<"FAIL";
}
}
}
cout<<endl;
}
return;
}
int main()
{
int _=1;
up(i,1,_,1){
solve();
}
return 0;
}