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