#include <bits/stdc++.h>
const int KSIZE = 11, MULTED = -1;
using namespace std;
struct vertex {
  vector<int> next;
  int parent_num;
};
vector<struct vertex> t;
vector<string> ans(70000, string("0000000000"));
void add(const string &s, int num) {
  int cur_v = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (t[cur_v].next[s[i] - '0']) {
      cur_v = t[cur_v].next[s[i] - '0'];
      if (num != t[cur_v].parent_num) t[cur_v].parent_num = MULTED;
    } else {
      t[cur_v].next[s[i] - '0'] = t.size();
      cur_v = t.size();
      t.push_back(vertex{vector<int>(KSIZE, 0), num});
    }
  }
}
void dfs(int v, string &way) {
  if (v > 0 && t[v].parent_num != MULTED &&
      way.size() < ans[t[v].parent_num].size())
    ans[t[v].parent_num] = way;
  for (int i = 0; i <= 9; i++)
    if (t[v].next[i]) {
      way.push_back((char)i + '0');
      dfs(t[v].next[i], way);
      way.pop_back();
    }
}
int main() {
  int n;
  cin >> n;
  t.push_back(vertex{vector<int>(KSIZE, 0), 0});
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < (int)s.size(); j++)
      add(s.substr(j, (int)s.size() - j), i);
  }
  string way = "";
  dfs(0, way);
  for (int i = 0; i < n; i++) cout << ans[i] << endl;
}
