#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n;
map <string, int> Service_machine;
bool check (string checker) {
int Number_of_dot = 0, Number_of_colon = 0;
int length = checker.size ();
for (int i = 0; i < length; i++) {
if (checker[i] == '.') Number_of_dot++;
if (checker[i] == ':') Number_of_colon++;
if (Number_of_dot < 3 && Number_of_colon >= 1) return false;
}
if (Number_of_dot != 3 || Number_of_colon != 1) return false;
int ans[10], subscript = 1; memset (ans, 0, sizeof (ans));
for (int i = 0; i < length; i++)
if (checker[i] == '.' || checker[i] == ':') subscript++;
else ans[subscript] = ans[subscript] * 10 + checker[i] - '0';
if (subscript != 5) return false;
for (int i = 1; i < 5; i++) if (!(ans[i] >= 0 && ans[i] <= 255)) return false;
if (!(ans[5] >= 0 && ans[5] <= 65535)) return false;
int The_distance_between_points[10], len = 1, last = 0;
for (int i = 0; i < length; i++)
if (checker[i] == '.' || checker[i] == ':') {
The_distance_between_points[len] = i - 1 - (last + 1) + 1;
last = i;
len++;
}
The_distance_between_points[5] = length - 1 - (last + 1) + 1;
for (int i = 0; i < length; i++)
if (checker[i] == '.') {
The_distance_between_points[1] = i;
break;
}
if (checker[0] == '0' && The_distance_between_points[1] >= 2) return false;
int pre = 2;
for (int i = 0; i < length; i++)
if (checker[i] == '.' || checker[i] == ':')
if (The_distance_between_points[pre] >= 2 && checker[i + 1] == '0') return false;
else pre++;
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
string type, num;
cin >> type >> num;
if (type == "Server") {
if (check (num)) {
if (Service_machine[num]) cout << "FAIL" << endl;
else if (Service_machine[num] == 0) cout << "OK" << endl, Service_machine[num] = i;
}
else cout << "ERR" << endl;
}
else if (type == "Client") {
if (check (num)) {
if (Service_machine[num]) cout << Service_machine[num] << endl;
else if (Service_machine[num] == 0) cout << "FAIL" << endl;
}
else cout << "ERR" << endl;
}
}
return 0;
}