#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
using namespace std;
set<string> server;
map<string,int> mp;
bool judge(int x, int y, int z)
{
if(x < y || x > z) return false;
return true;
}
bool check(string str)
{
stringstream fin(str);
int a, b, c, d, e;
char x, y, z, w;
fin>>a>>x>>b>>y>>c>>z>>d>>w>>e;
if(!judge(a,0,255) || !judge(b,0,255) || !judge(c,0,255) || !judge(d,0,255) || !judge(e,0,65535))
return false;
if(x != '.' || y != '.' || z != '.' || w != ':') return false;
string temp = to_string(a)+"."+to_string(b)+"."+to_string(c)+"."+to_string(d)+":"+to_string(e);
return temp == str;
}
int main()
{
int n;
cin>>n;
for(int i = 1; i <= n; i++)
{
string op, str;
cin>>op>>str;
bool ok = check(str);
if(op[0] == 'S')
{
if(!ok) cout<<"ERR"<<endl;
else
{
if(server.find(str) == server.end())
{
cout<<"OK"<<endl;
server.insert(str);
mp[str] = i;
}
else cout<<"FAIL"<<endl;
}
}
else
{
if(!ok) cout<<"ERR"<<endl;
else
{
if(server.find(str) != server.end())
{
map<string,int>::iterator it;
for(it = mp.begin(); it != mp.end(); it++)
{
string p = it->first;
if(p == str)
{
cout<<it->second<<endl;
break;
}
}
}
else cout<<"FAIL"<<endl;
}
}
}
return 0;
}
03-16
989
10-22
1050
10-26
853
10-29
1718
03-20
7009