#include <iostream>
#include <string>
#include <map>

using namespace std;

class username{
public:
    username(string a = "0");
    friend istream & operator >> (istream & in, username & a);
    friend ostream & operator << (ostream & out, username & a);
   // friend int isThere (int n, int a, username * base);
    friend bool operator < (const username a, const username b);

    string nick;
private:
    };

username::username(string a){
    nick = a;
}

istream & operator>>(istream &in, username &a){
	string name;
	in >> name;
	a = username(name);
	return in;
}
ostream & operator<<(ostream &out, username &a){
	out << a.nick;
	return out;
}


inline bool operator < (const username a, const username b){
    if (a.nick<b.nick)
        return 1;
    else return 0;
}

int main()
{
    std::ios::sync_with_stdio(false);
    int n = 0;
    cin >> n;
    string s;

    map < username,int > m;
    while(n--){cin>>s;
    if(m[s]++)
        cout<<s<<m[s]-1;
    else
        cout<<"OK";
    cout<<endl;}

    return 0;
}