#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 7e4 + 4;
const int A = 10;
string w[N];
int code(char x) { return x - '0'; }
const int V = N * 9 * 10 / 2;
int to[V][A], tn;
int cnt[V], lst[V];
void add(string s, int id) {
  int v = 0;
  for (char cc : s) {
    int c = code(cc);
    if (!to[v][c]) {
      to[v][c] = ++tn;
    }
    v = to[v][c];
    if (lst[v] < id) {
      ++cnt[v];
      lst[v] = id;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cerr << sizeof(to) / (1 << 20) << endl;
  int n, m;
  cin >> n;
  for (int k = 1; k <= n; ++k) {
    string s;
    cin >> s;
    w[k] = s;
    for (int i = 0; i < 9; ++i) add(s.substr(i), k);
  }
  for (int k = 1; k <= n; ++k) {
    string s = w[k];
    string res = s;
    for (int i = 0; i < 9; ++i) {
      string t;
      int v = 0;
      for (int j = i; j < 9; ++j) {
        t += s[j];
        int c = code(s[j]);
        v = to[v][c];
        if (cnt[v] == 1) {
          if (res.size() > t.size()) res = t;
          break;
        }
      }
    }
    cout << res << '\n';
  }
  return 0;
}
