#include<bits/stdc++.h>
#include <cmath>
using namespace std;
/* 1 x y
* 2 x */
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);;
int n;
cin>>n;
map <string, int> mp;
for(int i=0;i<n;i++) {
string s;
cin>>s;
if (mp[s]==0) {
cout<<"OK\n";
mp[s]=1;
}
else {
cout<<s<<mp[s]<<"\n";
mp[s]++;
}
}
return 0;
}
ICNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxjbWF0aD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8qIDEgeCB5CiAqIDIgeCAqLwoKaW50IG1haW4oKSB7CiBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKIGNpbi50aWUoTlVMTCk7CiBjb3V0LnRpZShOVUxMKTs7CgogaW50IG47CiBjaW4+Pm47CiBtYXAgPHN0cmluZywgaW50PiBtcDsKIGZvcihpbnQgaT0wO2k8bjtpKyspIHsKICBzdHJpbmcgczsKICBjaW4+PnM7CiAgaWYgKG1wW3NdPT0wKSB7CiAgIGNvdXQ8PCJPS1xuIjsKICAgbXBbc109MTsKICB9CiAgZWxzZSB7CgogICBjb3V0PDxzPDxtcFtzXTw8IlxuIjsKICAgbXBbc10rKzsKICB9CiB9CgoKCiByZXR1cm4gMDsKfQo=