#include <bits/stdc++.h>
using namespace std;
// Uzumaki Naruto :)
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl
#define dbg(A,sz) for(int i = 0; i < sz; ++i) cerr << A[i] << " "; cerr << "\n"
#define CLR(A,sz) for(int i = 0; i < sz; ++i) A[i] = 0;
#define pause() cin.get();cin.get();
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
const int MM = 1123;
const int NN = 112345;
int od[20][NN],t[NN][2];
int A[NN],B[NN],C[NN],D[NN];
int st[MM],ed[MM],Map[NN];
int nxt[NN],prev[NN];
int Mstp,Mcnt,N,sz;
string inp[MM],fin;
void Build(){
CLR(A,300);
for(int i = 0; i < sz; ++i) A[(int)fin[i]] = 1;
for(int i = 1; i < 300; ++i) A[i] += A[i-1];
for(int i = 0; i < sz; ++i)
od[0][i] = A[(int)fin[i]];
CLR(A,300);
int stp = 1, cnt = 1,k;
for(; cnt < sz; cnt <<= 1, ++stp){
CLR(A,sz+10);
CLR(B,sz+10);
for(int i = 0; i < sz; ++i)
++A[t[i][0] = od[stp-1][i]], ++B[t[i][1] = ((i+cnt < sz) ? od[stp-1][i+cnt] : 0)];
for(int i = 1; i <= sz; ++i)
A[i] += A[i-1], B[i] += B[i-1];
for(int i = sz-1; i >= 0; --i)
C[--B[t[i][1]]] = i;
for(int i = sz-1; i >= 0; --i)
k = C[i], D[--A[t[k][0]]] = k;
k = od[stp][D[0]] = 1;
for(int i = 1; i < sz; ++i){
int id1 = D[i], id2 = D[i-1];
od[stp][id1] = (k += (t[id1][1] != t[id2][1] or t[id1][0] != t[id2][0]));
}
}
Mcnt = cnt, Mstp = stp-1;
}
int LCP(int x,int y){
if (x == -1 or y == -1) return 0;
int res = 0, stp = Mstp , cnt = Mcnt;
for(; stp >= 0; --stp, cnt >>= 1)
if (x+cnt <= sz and y+cnt <= sz and od[stp][x] == od[stp][y])
res += cnt, x += cnt, y += cnt;
return res;
}
void solve(){
cin >> N;
fin = ""; sz = 0;
for(int i = 0; i < N; ++i) {
cin >> inp[i];
st[i] = sz, ed[i] = sz+(int)inp[i].size()-1;
for(int j = 0; j < (int)inp[i].size(); ++j)
Map[sz++] = i, fin.push_back(inp[i][j]);
}
assert(sz < NN);
Build();
int i = 0, j = 0;
while(i < sz){
while(j < sz and Map[D[j]] == Map[D[i]]) ++j;
int ans = (j < sz ? D[j] : -1);
while(i < j) nxt[D[i++]] = ans;
}
i = j = sz-1;
while(i >= 0){
while(j >= 0 and Map[D[j]] == Map[D[i]]) --j;
int ans = (j >= 0 ? D[j] : -1);
while(i > j) prev[D[i--]] = ans;
}
for(int i = 0; i < N; ++i){
int ans = INT_MAX,id,res;
for(int j = st[i]; j <= ed[i]; ++j){
int p1 = LCP(j,nxt[j]), p2 = LCP(j,prev[j]);
res = max(p1,p2);
if (res >= ed[i]-j+1) continue;
if (res < ans) ans = res, id = j;
}
assert(ans != INT_MAX);
for(int j = 0; j <= ans; ++j) cout << fin[id+j];
cout << "\n";
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyBVenVtYWtpIE5hcnV0byA6KQoKI2RlZmluZSBEQihhKSBjZXJyIDw8IF9fTElORV9fIDw8ICI6ICIgPDwgI2EgPDwgIiA9ICIgPDwgKGEpIDw8IGVuZGwKI2RlZmluZSBkYmcoQSxzeikgZm9yKGludCBpID0gMDsgaSA8IHN6OyArK2kpIGNlcnIgPDwgQVtpXSA8PCAiICI7IGNlcnIgPDwgIlxuIgojZGVmaW5lIENMUihBLHN6KSBmb3IoaW50IGkgPSAwOyBpIDwgc3o7ICsraSkgQVtpXSA9IDA7CiNkZWZpbmUgcGF1c2UoKSBjaW4uZ2V0KCk7Y2luLmdldCgpOwp0eXBlZGVmIGxvbmcgbG9uZyBMTDsKdHlwZWRlZiBwYWlyPGludCxpbnQ+IFBJSTsKdHlwZWRlZiB2ZWN0b3I8aW50PiBWSTsKCmNvbnN0IGludCBNTSA9IDExMjM7CmNvbnN0IGludCBOTiA9IDExMjM0NTsKCmludCBvZFsyMF1bTk5dLHRbTk5dWzJdOwppbnQgQVtOTl0sQltOTl0sQ1tOTl0sRFtOTl07CgppbnQgc3RbTU1dLGVkW01NXSxNYXBbTk5dOwppbnQgbnh0W05OXSxwcmV2W05OXTsKaW50IE1zdHAsTWNudCxOLHN6OwpzdHJpbmcgaW5wW01NXSxmaW47Cgp2b2lkIEJ1aWxkKCl7CiAgICBDTFIoQSwzMDApOwogICAgZm9yKGludCBpID0gMDsgaSA8IHN6OyArK2kpIEFbKGludClmaW5baV1dID0gMTsKICAgIGZvcihpbnQgaSA9IDE7IGkgPCAzMDA7ICsraSkgQVtpXSArPSBBW2ktMV07CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgc3o7ICsraSkKICAgICAgICBvZFswXVtpXSA9IEFbKGludClmaW5baV1dOwoKICAgIENMUihBLDMwMCk7CiAgICBpbnQgc3RwID0gMSwgY250ID0gMSxrOwogICAgZm9yKDsgY250IDwgc3o7IGNudCA8PD0gMSwgKytzdHApewogICAgICAgIENMUihBLHN6KzEwKTsKICAgICAgICBDTFIoQixzeisxMCk7CgogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBzejsgKytpKQogICAgICAgICAgICArK0FbdFtpXVswXSA9IG9kW3N0cC0xXVtpXV0sICsrQlt0W2ldWzFdID0gKChpK2NudCA8IHN6KSA/IG9kW3N0cC0xXVtpK2NudF0gOiAwKV07CiAgICAgICAgZm9yKGludCBpID0gMTsgaSA8PSBzejsgKytpKQogICAgICAgICAgICBBW2ldICs9IEFbaS0xXSwgQltpXSArPSBCW2ktMV07CiAgICAgICAgZm9yKGludCBpID0gc3otMTsgaSA+PSAwOyAtLWkpCiAgICAgICAgICAgIENbLS1CW3RbaV1bMV1dXSA9IGk7CiAgICAgICAgZm9yKGludCBpID0gc3otMTsgaSA+PSAwOyAtLWkpCiAgICAgICAgICAgIGsgPSBDW2ldLCBEWy0tQVt0W2tdWzBdXV0gPSBrOwoKICAgICAgICBrID0gb2Rbc3RwXVtEWzBdXSA9IDE7CiAgICAgICAgZm9yKGludCBpID0gMTsgaSA8IHN6OyArK2kpewogICAgICAgICAgICBpbnQgaWQxID0gRFtpXSwgaWQyID0gRFtpLTFdOwogICAgICAgICAgICBvZFtzdHBdW2lkMV0gPSAoayArPSAodFtpZDFdWzFdICE9IHRbaWQyXVsxXSBvciB0W2lkMV1bMF0gIT0gdFtpZDJdWzBdKSk7CiAgICAgICAgfQogICAgfQogICAgTWNudCA9IGNudCwgTXN0cCA9IHN0cC0xOwp9CgppbnQgTENQKGludCB4LGludCB5KXsKICAgIGlmICh4ID09IC0xIG9yIHkgPT0gLTEpIHJldHVybiAwOwogICAgaW50IHJlcyA9IDAsIHN0cCA9IE1zdHAgLCBjbnQgPSBNY250OwogICAgZm9yKDsgc3RwID49IDA7IC0tc3RwLCBjbnQgPj49IDEpCiAgICAgICAgaWYgKHgrY250IDw9IHN6IGFuZCB5K2NudCA8PSBzeiBhbmQgb2Rbc3RwXVt4XSA9PSBvZFtzdHBdW3ldKQogICAgICAgICAgICByZXMgKz0gY250LCB4ICs9IGNudCwgeSArPSBjbnQ7CiAgICByZXR1cm4gcmVzOwp9Cgp2b2lkIHNvbHZlKCl7CiAgICBjaW4gPj4gTjsKICAgIGZpbiA9ICIiOyBzeiA9IDA7CgogICAgZm9yKGludCBpID0gMDsgaSA8IE47ICsraSkgewogICAgICAgIGNpbiA+PiBpbnBbaV07CiAgICAgICAgc3RbaV0gPSBzeiwgZWRbaV0gPSBzeisoaW50KWlucFtpXS5zaXplKCktMTsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgKGludClpbnBbaV0uc2l6ZSgpOyArK2opCiAgICAgICAgICAgIE1hcFtzeisrXSA9IGksIGZpbi5wdXNoX2JhY2soaW5wW2ldW2pdKTsKICAgIH0KCiAgICBhc3NlcnQoc3ogPCBOTik7CiAgICBCdWlsZCgpOwogICAgaW50IGkgPSAwLCBqID0gMDsKICAgIHdoaWxlKGkgPCBzeil7CiAgICAgICAgd2hpbGUoaiA8IHN6IGFuZCBNYXBbRFtqXV0gPT0gTWFwW0RbaV1dKSArK2o7CiAgICAgICAgaW50IGFucyA9IChqIDwgc3ogPyBEW2pdIDogLTEpOwogICAgICAgIHdoaWxlKGkgPCBqKSBueHRbRFtpKytdXSA9IGFuczsKICAgIH0KCiAgICBpID0gaiA9IHN6LTE7CiAgICB3aGlsZShpID49IDApewogICAgICAgIHdoaWxlKGogPj0gMCBhbmQgTWFwW0Rbal1dID09IE1hcFtEW2ldXSkgLS1qOwogICAgICAgIGludCBhbnMgPSAoaiA+PSAwID8gRFtqXSA6IC0xKTsKICAgICAgICB3aGlsZShpID4gaikgcHJldltEW2ktLV1dID0gYW5zOwogICAgfQoKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBOOyArK2kpewogICAgICAgIGludCBhbnMgPSBJTlRfTUFYLGlkLHJlczsKICAgICAgICBmb3IoaW50IGogPSBzdFtpXTsgaiA8PSBlZFtpXTsgKytqKXsKICAgICAgICAgICAgaW50IHAxID0gTENQKGosbnh0W2pdKSwgcDIgPSBMQ1AoaixwcmV2W2pdKTsKICAgICAgICAgICAgcmVzID0gbWF4KHAxLHAyKTsKICAgICAgICAgICAgaWYgKHJlcyA+PSBlZFtpXS1qKzEpIGNvbnRpbnVlOwogICAgICAgICAgICBpZiAocmVzIDwgYW5zKSBhbnMgPSByZXMsIGlkID0gajsKICAgICAgICB9CiAgICAgICAgYXNzZXJ0KGFucyAhPSBJTlRfTUFYKTsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDw9IGFuczsgKytqKSBjb3V0IDw8IGZpbltpZCtqXTsKICAgICAgICBjb3V0IDw8ICJcbiI7CiAgICB9Cn0KCmludCBtYWluKCkKewoJaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKCWNpbi50aWUoTlVMTCk7Cglzb2x2ZSgpOwoJcmV0dXJuIDA7Cn0K