#include <bits/stdc++.h>
using namespace std;
const int N = 70500;
const int M = 11;
char a[N][M];
int n, m = 9;
struct Info {
  int belong;
  int val;
} xu[5000000];
int ans[N];
int cc;
int find(int x, int y, int z) {
  int i;
  int res = 0;
  for (i = z; i >= y; i--) res = res * 10 + (a[x][i] - '0');
  return res;
}
bool cmp(Info x, Info y) {
  if (x.val < y.val) return 1;
  if (x.val > y.val) return 0;
  return (x.belong < y.belong);
}
void pr(int x) {
  int t = x % 10;
  x /= 10;
  while (t--) {
    putchar(x % 10 + '0');
    x /= 10;
  }
  putchar('\n');
}
int main() {
  scanf("%d", &n);
  int i, j, k, l;
  for (i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      for (k = j; k <= m; k++) {
        if (j == 1 && k == m) continue;
        int now = find(i, j, k);
        now = now * 10 + (k - j + 1);
        cc++;
        xu[cc].val = now;
        xu[cc].belong = i;
      }
    }
  }
  sort(xu + 1, xu + cc + 1, cmp);
  for (i = 1; i <= cc; i++) {
    int s = i;
    while (i < cc && xu[i].val == xu[i + 1].val) i++;
    for (j = s + 1; j <= i; j++) {
      if (xu[j].belong != xu[j - 1].belong) break;
    }
    if (j > i) {
      int now = xu[i].val;
      int bl = xu[i].belong;
      if (!ans[bl])
        ans[bl] = now;
      else if (ans[bl] % 10 > now % 10)
        ans[bl] = now;
    }
  }
  for (i = 1; i <= n; i++) {
    if (ans[i])
      pr(ans[i]);
    else
      printf("%s\n", a[i] + 1);
  }
  return 0;
}
