#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
using namespace std;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
int t; cin >> t;
map<string, int>m;
while (t--) {
string s; cin >> s;
int cnt = 0;
if (!m.count(s)) {
cout << "ok\n";
m[s]++;
}
else {
while (m.count(s + to_string(m[s]))) {
m[s]++;
}
s = s + to_string(m[s]);
cout << s << "\n";
m[s]++;
}
}
return 0;
}