#include <bits/stdc++.h>
using namespace std;
struct vertex {
  int zn;
  int coun;
  int p1;
  int sl[10];
  int prev;
};
struct number {
  int coun;
  int ss;
};
int n;
vector<vertex> y(10);
vector<vector<number> > v(70000, vector<number>(9));
vector<vector<int> > res(70000, {-1});
int ost = 0;
int u = 0;
void pruf() {
  u++;
  vector<int> r(1);
  r[0] = -1;
  while (ost < (int)y.size()) {
    if (y[ost].coun == 1) {
      if (res[y[ost].p1] == r) {
        res[y[ost].p1] = {};
        int q = ost;
        while (y[q].prev != -1) {
          res[y[ost].p1].push_back(y[q].zn);
          q = y[q].prev;
        }
        res[y[ost].p1].push_back(y[q].zn);
        reverse(res[y[ost].p1].begin(), res[y[ost].p1].end());
      }
    }
    ost++;
  }
  return;
}
int main() {
  cin >> n;
  for (int i = 0; i < 10; i++) {
    y[i].zn = i;
    y[i].coun = 0;
    for (int j = 0; j < 10; j++) y[i].sl[j] = -1;
    y[i].prev = -1;
    y[i].p1 = -1;
  }
  string r;
  for (int i = 0; i < n; i++) {
    cin >> r;
    for (int j = 0; j < 9; j++) {
      v[i][j].coun = r[j] - '0';
      v[i][j].ss = r[j] - '0';
      if (y[v[i][j].ss].p1 != i) {
        y[v[i][j].ss].p1 = i;
        y[v[i][j].ss].coun++;
      }
    }
  }
  pruf();
  vertex d;
  d.zn = 0;
  d.coun = 1;
  for (int j = 0; j < 10; j++) d.sl[j] = -1;
  d.prev = -1;
  d.p1 = -1;
  for (int i = 1; i < 9; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 8; k >= i; k--) {
        if (y[v[j][k - 1].ss].sl[v[j][k].coun] == -1) {
          y.push_back(d);
          int a = (int)y.size() - 1;
          y[a].zn = v[j][k].coun;
          y[a].prev = v[j][k - 1].ss;
          y[a].p1 = j;
          v[j][k].ss = a;
          y[v[j][k - 1].ss].sl[v[j][k].coun] = a;
        } else {
          if (y[y[v[j][k - 1].ss].sl[v[j][k].coun]].p1 == j) {
            v[j][k].ss = y[v[j][k - 1].ss].sl[v[j][k].coun];
          } else {
            v[j][k].ss = y[v[j][k - 1].ss].sl[v[j][k].coun];
            y[y[v[j][k - 1].ss].sl[v[j][k].coun]].p1 = j;
            y[y[v[j][k - 1].ss].sl[v[j][k].coun]].coun += 1;
          }
        }
      }
    }
    pruf();
  }
  for (int i = 0; i < n; i++) {
    for (auto j : res[i]) {
      cout << j;
    }
    cout << endl;
  }
  return 0;
}
