#include <bits/stdc++.h>
using namespace std;
int const inf = 1000 * 1000 * 1000;
long long const inf64 = 1ll * inf * inf;
int const N = 7e4 + 5;
char buff[100];
inline void getLine(string& s) {
  scanf("%s", buff);
  s = buff;
}
int n;
string s[N];
unordered_set<string> st[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    getLine(s[i]);
  }
  unordered_map<string, int> mp(n * 36);
  for (int i = 1; i <= n; i++) {
    string cur = "";
    for (int l = 0; l < 9; l++) {
      cur = "";
      for (int r = l; r < 9; r++) {
        cur.push_back(s[i][r]);
        st[i].insert(cur);
      }
    }
    for (string str : st[i]) {
      mp[str]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    string res = "-1";
    for (string str : st[i]) {
      if (mp[str] == 1) {
        if (res == "-1" || res.size() > str.size()) {
          res = str;
        }
      }
    }
    for (char c : res) {
      printf("%c", c);
    }
    printf("\n");
  }
  return 0;
}
