#include <iostream>
#include <string>

using namespace std;

class username{
public:
    username(string a = "A");
    friend istream & operator >> (istream & in, username & a);
    friend ostream & operator << (ostream & out, username & a);
    friend int isThere (int n, int a, username * base);
private:
    string nick;
    };

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;
}

int isThere (int n, int curPos, username * base){
    int c = 0;
    for(int i = 0; i < n; i++)
        if(base[curPos].nick == base[i].nick)
            c++;
    return c;
}

int main()
{
    std::ios::sync_with_stdio(false);
    int n = 0;
    cin >> n;
    username* nBase = new username[n];
    for(int i = 0; i<n; i++){
        cin >> nBase [i];
        int counter = isThere(i, i, nBase);
        if(counter == 0)
            cout << "OK" << endl;
        else
            cout << nBase[i] << counter << endl;
    }
	return 0;
}