#include <bits/stdc++.h>
using namespace std;
struct Node {
  int r;
  int a[10];
  Node() {
    r = 0;
    for (int i = 0; i <= 9; i++) {
      a[i] = 0;
    }
  }
};
vector<Node> t;
void insert(string s) {
  int r = 0;
  for (int i = 0; i < int(s.size()); i++) {
    if (t[r].a[s[i] - '0'] == 0) {
      t.push_back(Node());
      t[r].a[s[i] - '0'] = int(t.size()) - 1;
    }
    r = t[r].a[s[i] - '0'];
  }
  t[r].r++;
  return;
}
int exist(string s) {
  int r = 0;
  for (int i = 0; i < int(s.size()); i++) {
    if (t[r].a[s[i] - '0'] == 0) return false;
    r = t[r].a[s[i] - '0'];
  }
  return t[r].r;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  t.push_back(Node());
  vector<string> d(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    d[i] = s;
    set<string> q;
    for (int j = 0; j < int(s.size()); j++) {
      string w = "";
      for (int e = j; e < int(s.size()); e++) {
        w.push_back(s[e]);
        if (q.find(w) == q.end()) insert(w);
        q.insert(w);
      }
    }
  }
  vector<string> ans;
  for (int i = 0; i < n; i++) {
    string s = d[i];
    for (int j = 1; j <= int(s.size()); j++) {
      for (int e = 0; e <= int(s.size()) - j; e++) {
        if (exist(s.substr(e, j)) == 1) {
          ans.push_back(s.substr(e, j));
          goto M;
        }
      }
    }
    cout << -1 << '\n';
    return 0;
  M:;
  }
  for (int i = 0; i < int(ans.size()); i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
