#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 70100;
int n;
int a[maxn + 5];
int pw[11];
map<int, pair<int, int> > all;
int main() {
  pw[0] = 1;
  for (int i = (0), i_end_ = (10); i < i_end_; ++i) pw[i + 1] = pw[i] * 10;
  scanf("%d", &n);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) scanf("%d", a + i);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    for (int j = (0), j_end_ = (9); j < j_end_; ++j)
      for (int k = (j + 1), k_end_ = (10); k < k_end_; ++k) {
        int tmp = a[i] / pw[j] % pw[k - j] + pw[k - j];
        if (!all.count(tmp))
          all[tmp] = make_pair(i, i);
        else
          chkmax(all[tmp].second, i);
      }
  }
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    int len = oo, ans = -1;
    for (int j = (0), j_end_ = (9); j < j_end_; ++j)
      for (int k = (j + 1), k_end_ = (10); k < k_end_; ++k) {
        int tmp = a[i] / pw[j] % pw[k - j] + pw[k - j];
        if (all[tmp] == make_pair(i, i) && chkmin(len, k - j)) ans = tmp;
      }
    for (int j = len - 1; j >= 0; --j) printf("%d", int(ans / pw[j] % 10));
    printf("\n");
  }
  return 0;
}
