#include <bits/stdc++.h>
#define endl "\n"
#define Dark_knight
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    map<string,int> st;
    int n ; cin>>n;
    while(n--) {
        string s ; cin>>s;
        if(st[s]==0) {
            cout<<"OK"<<endl;
            st[s]++;
        }
        else {
            cout<<s<<st[s]<<endl;
            st[s]++;
        }
        }



}
