#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAXN ('z'-'a'+2)
#define VALUE(c) ( (c)-'a' )
struct Trie
{
Trie *m[MAXN];
int count;
}trie;
int insert(Trie * t, char * w){
if(w[0]=='\0'){
t->count++;
return t->count;
}
if(t->m[VALUE(w[0])] == NULL){
t->m[VALUE(w[0])] =(Trie *) malloc(sizeof(Trie));
}
return insert(t->m[VALUE(w[0])] , w+1);
}
int main(){
int t;
scanf("%d",&t);
for (int i = 0; i < t; ++i)
{
char *w = NULL;
w = (char *)malloc(sizeof(char));
scanf("%s",w);
//printf("%s\n", w);
int resp = insert(&trie,w);
if(resp > 1){
printf("%s%d\n", w,resp-1);
}else{
printf("OK\n");
}
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgTUFYTiAgKCd6Jy0nYScrMikKI2RlZmluZSBWQUxVRShjKSAoIChjKS0nYScgKQoKc3RydWN0IFRyaWUKewoJVHJpZSAqbVtNQVhOXTsKCWludCBjb3VudDsKfXRyaWU7CgppbnQgaW5zZXJ0KFRyaWUgKiAgdCwgY2hhciAqIHcpewoJaWYod1swXT09J1wwJyl7CgkJdC0+Y291bnQrKzsKCQlyZXR1cm4gdC0+Y291bnQ7Cgl9CglpZih0LT5tW1ZBTFVFKHdbMF0pXSA9PSBOVUxMKXsKCQl0LT5tW1ZBTFVFKHdbMF0pXSA9KFRyaWUgKikgbWFsbG9jKHNpemVvZihUcmllKSk7Cgl9CglyZXR1cm4gaW5zZXJ0KHQtPm1bVkFMVUUod1swXSldICwgdysxKTsKfQkKCgppbnQgbWFpbigpewoKCWludCB0OwoJc2NhbmYoIiVkIiwmdCk7CgoJZm9yIChpbnQgaSA9IDA7IGkgPCB0OyArK2kpCgl7CgkJY2hhciAqdyA9IE5VTEw7CgkgICAgdyA9IChjaGFyICopbWFsbG9jKHNpemVvZihjaGFyKSk7CgkgICAgc2NhbmYoIiVzIix3KTsKCSAgICAvL3ByaW50ZigiJXNcbiIsIHcpOwoJCWludCByZXNwID0gaW5zZXJ0KCZ0cmllLHcpOwkKCQlpZihyZXNwID4gMSl7CgkJCXByaW50ZigiJXMlZFxuIiwgdyxyZXNwLTEpOwoJCX1lbHNlewoJCQlwcmludGYoIk9LXG4iKTsKCQl9Cgl9CgoKCXJldHVybiAwOwoKfQ==