#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 10;
map<string,int> mp;
map<string,int> mp2;
int n;
string str;
char ch[N];
bool flag;
int dou,mao;
bool is255;
int temp;
bool check(){
for(int i = 1;i<=str.size();i++){
temp = 0;
if('0'<=str[i] && str[i]<='9'){
while('0'<=str[i] && str[i]<='9'){
temp = temp * 10 + str[i] - '0';
i++;
}
}
if(str[i] == '.') dou++;
if(str[i] == ':') mao++;
if(str[i] == '.' || str[i] == ':'){
if(str[i+1] == '0' && 0<=str[i+2] && 9>=str[i+2] && str[i+2] != ':' && str[i+2] != '.') return false;
if(str[i+1] < '0' || str[i+1] > '9') return false;
}
if(str[i] == '.'){
if(str[i+1] == '.' || str[i+1] == ':'){
return false;
}
}
if(is255 == true){
if(temp < 0 || temp > 255){
return false;
}
}else{
if(temp < 0 || temp > 65535){
return false;
}
}
if(str[i] == ':'){
is255 = false;
if(str[i+1] == '.' || str[i+1] == ':'){
return false;
}
if(dou != 3){
return false;
}
}
}
if(mao != 1) return false;
if(dou != 3) return false;
return true;
}
signed main(){
cin>>n;
for(int i = 1;i<=n;i++){
cin>>ch;
getline(cin,str);
flag = true;
is255 = true;
dou = 0;
mao = 0;
temp = 0;
if(check() == false){
cout<<"ERR"<<endl;
continue;
}
if(ch[0] == 'S'){
if(mp[str] > 0){
cout<<"FAIL"<<endl;
}else{
cout<<"OK"<<endl;
mp[str] = i;
}
}else{
if(mp[str] == 0){
cout<<"FAIL"<<endl;
}else{
cout<<mp[str]<<endl;
mp2[str] = i;
}
}
}
return 0;
}