#include <bits/stdc++.h>
using namespace std;
const int MAX = 70010;
int n;
char s[MAX][10];
pair<int, int> res;
struct Trie {
  int cnt;
  int child[10];
  static void insert(const int& offset, char* s);
  static void remove(const int& offset, char* s);
  static int find(const int& offset, char* s);
} trie[MAX * 20];
int pool = 1;
void Trie::insert(const int& offset, char* s) {
  int cur = 1;
  for (int i = offset; i < 9; ++i) {
    if (trie[cur].child[s[i] - '0'] == 0) trie[cur].child[s[i] - '0'] = ++pool;
    cur = trie[cur].child[s[i] - '0'];
    ++trie[cur].cnt;
  }
}
void Trie::remove(const int& offset, char* s) {
  int cur = 1;
  for (int i = offset; i < 9; ++i) {
    cur = trie[cur].child[s[i] - '0'];
    --trie[cur].cnt;
  }
}
int Trie::find(const int& offset, char* s) {
  int cur = 1;
  for (int i = offset; i < 9; ++i) {
    cur = trie[cur].child[s[i] - '0'];
    if (trie[cur].cnt == 0) return i;
  }
  return -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
    for (int offset = 0; offset < 9; ++offset) Trie::insert(offset, s[i]);
  }
  for (int i = 0, len, tail; i < n; ++i) {
    for (int offset = 0; offset < 9; ++offset) Trie::remove(offset, s[i]);
    len = MAX;
    for (int offset = 0; offset < 9; ++offset) {
      tail = Trie::find(offset, s[i]);
      if (tail != -1 && tail - offset < len) {
        res = pair<int, int>(offset, tail);
        len = tail - offset;
      }
    }
    for (int offset = 0; offset < 9; ++offset) Trie::insert(offset, s[i]);
    for (int j = res.first; j <= res.second; ++j) printf("%c", s[i][j]);
    printf("\n");
  }
  return 0;
}
