#include <bits/stdc++.h>
using namespace std;
template <class T>
bool cmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool cmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int N = 70005;
char S[N][10];
pair<int, long long> ans[N];
vector<pair<int, long long> > has[N];
vector<pair<int, long long> > cand[N];
int s[20];
void print(long long x, int len) {
  int c = x == 0;
  if (x == 0) s[0] = 0;
  while (x > 0) {
    s[c++] = x % 10;
    x /= 10;
  }
  int zeros = len - c;
  for (int i = 0; i < zeros; i++) printf("0");
  for (int i = c - 1; i >= 0; i--) printf("%d", s[i]);
  puts("");
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", S[i]);
    for (int j = 0; j < 9; j++) {
      long long x = 0;
      for (int k = j; k < 9; k++) {
        x = x * 10 + S[i][k] - '0';
        has[i].emplace_back(k - j + 1, x);
      }
    }
    cand[i] = has[i];
  }
  for (int it = 0; it < 2; it++) {
    set<pair<int, long long> > cnt;
    for (int ii = 0; ii < n; ii++) {
      int i = it == 0 ? ii : n - ii - 1;
      vector<pair<int, long long> > ncand;
      for (auto p : cand[i]) {
        if (!cnt.count(p)) {
          ncand.push_back(p);
        }
      }
      cand[i] = ncand;
      for (auto p : has[i]) cnt.insert(p);
    }
  }
  for (int i = 0; i < n; i++) {
    auto p = *min_element(cand[i].begin(), cand[i].end());
    print(p.second, p.first);
  }
  return 0;
}
