/*这道题意简单不多说了,主要是应该熟练stl库的用法*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int maxn = 1e5+10;
map<string, int>s;
int main()
{
int n;
while(scanf("%d", &n) != EOF){
for(int i = 0; i < n; i++){
string str;
cin >> str;
s[str]++;
if(s[str] == 1) cout << "OK" << endl;
else cout << str << s[str] - 1 << endl;
}
s.clear();
}
return 0;
}