#include <bits/stdc++.h>
using namespace std;
struct node {
  node(int index) {
    only_num = index;
    is_only = true;
  }
  int e[10] = {0};
  int only_num;
  bool is_only;
};
const int root = 0;
vector<node> buffer(1, node(0));
void add_str(const string& str, int start, int index) {
  int cur = root;
  for (int i = start; i < str.size(); ++i) {
    char c = str[i];
    int edge = c - '0';
    if (buffer[cur].e[edge] == 0) {
      buffer[cur].e[edge] = buffer.size();
      buffer.push_back(node(index));
    } else if (buffer[buffer[cur].e[edge]].only_num != index)
      buffer[buffer[cur].e[edge]].is_only = false;
    cur = buffer[cur].e[edge];
  }
}
int solve() {
  int n;
  cin >> n;
  vector<string> ans(n);
  for (int i = 0; i < n; ++i) {
    string num;
    cin >> num;
    for (int start = 0; start < num.size(); ++start) add_str(num, start, i);
  }
  stack<pair<int, char>> st;
  st.push(make_pair(root, ' '));
  string cur_str;
  int cur_nd;
  char cur_ch;
  while (!st.empty()) {
    tie(cur_nd, cur_ch) = st.top();
    st.pop();
    if (cur_nd < 0) {
      cur_str.pop_back();
      continue;
    }
    if (cur_nd != root) st.push(make_pair(-cur_nd, cur_ch));
    if (cur_nd != root) cur_str += cur_ch;
    if (cur_nd != root && buffer[cur_nd].is_only) {
      int to = buffer[cur_nd].only_num;
      if (ans[to].size() == 0 || ans[to].size() > cur_str.size())
        ans[to] = cur_str;
      continue;
    }
    for (int i = 0; i < 10; ++i) {
      if (!buffer[cur_nd].e[i]) continue;
      st.push(make_pair(buffer[cur_nd].e[i], '0' + i));
      if (cur_nd == root) buffer[cur_nd].e[i] = 0;
    }
  }
  for (auto& s : ans) {
    cout << s << endl;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
