#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
map<string,ll> st;
vector<vector<ll>> v;
string res[70005];
void solve(){
	ll n;
	cin>>n;
	set<string> s;
	for(ll i=0;i<n;i++){
		string t;
		cin>>t;
		for(ll j=0;j<9;j++)
		for(ll len=1;len<=9;len++)
		if(j+len-1<9){
			string temp=t.substr(j,len);
			if(st.find(temp)==st.end()){
				st.insert({temp,ll(st.size())});
				v.push_back(vector<ll>());
			}
			v[st[temp]].push_back(i);
		}
		res[i]=t;
	}
	for(auto it=st.begin();it!=st.end();it++){
		ll sz=ll((it->first).length()),i=it->second;
		ll f=0,a=v[i][0];
		for(ll j=0;j<ll(v[i].size());j++)
		if(v[i][j]!=a){
			f=1;
			break;
		}
		if(f)
		continue;
		if(ll(res[a].length())>sz)
		res[a]=it->first;
	}
	for(ll i=0;i<n;i++)
	cout<<res[i]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
map<string,ll> st;
string res[70005];
void solve(){
	ll n;
	cin>>n;
	set<string> s;
	for(ll i=0;i<n;i++){
		string t;
		cin>>t;
		set<string> dum;
		for(ll j=0;j<9;j++)
		for(ll len=1;len<=9;len++)
		if(j+len-1<9){
			string temp=t.substr(j,len);
			if(s.find(temp)!=s.end()||st.find(temp)!=st.end())
			st.erase(temp);
			else
			dum.insert(temp);
		}
		for(ll j=0;j<9;j++)
		for(ll len=1;len<=9;len++)
		if(j+len-1<9){
			string temp=t.substr(j,len);
			s.insert(temp);
		}
		for(auto it=dum.begin();it!=dum.end();it++)
		st.insert({*it,i});
		res[i]=t;
	}
	for(auto it=st.begin();it!=st.end();it++)
	if(ll(res[it->second].length())>ll((it->first).length()))
	res[it->second]=it->first;
	for(ll i=0;i<n;i++)
	cout<<res[i]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265
#define pb push_back
#define en cout<<'\n'
#define vec vector<ll>
#define vecs vector<string>
#define pii pair<double,double>
#define VP vector< pii >
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x) ud __builtin_ctzll(x)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define mm " "
#define MM " "
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define INF (ll)(9e18)
#define Sort(v) sort(v.begin(),v.end())
#define test ll T;cin>>T;while(T--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())
 const ll MOD=1000000000+7;
const ll MOD1 = 998244353;
   ll mod(ll x){
        return (x%MOD + MOD)%MOD;
    }
    ll mul(ll a , ll b){
        return mod(mod(a)*mod(b));
    }
string itos(ll s)
{
string str=to_string(s);
return str;
}
ll stoi2(string s)
{
    ll a= atoi(s.c_str());
    return a;
}
ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

bool isSubSequence(string str1, string str2, int m, int n)
{

    if (m == 0) return true;
    if (n == 0) return false;

    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);

    return isSubSequence(str1, str2, m, n-1);
}

bool ispalindrome(ll len,string str)
{

    for(int i = 0; i < len/2; i++){
        if(str[i] != str[len-1-i]){
            return false;
        }
    }
    return true;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll isprime(ll N){
    if(N<2 || (!(N&1) && N!=2))
        return 0;
    for(ll i=3; i*i<=N; i+=2){
        if(!(N%i))
            return 0;
    }
    return 1;
}
vec factor;
void factors(ll n)
{

for(ll i=1;i<=sqrt(n);i++)
{
    if(n%i==0)
    {
        if(i==n/i)
        factor.pb(i);
        else
        {
            factor.pb(i);
            factor.pb(n/i);
        }

    }
}

sort(all(factor));
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
	return (a/gcd(a,b))*b;
}
bool isvalid(ll i,ll j,ll n)
{
    if(i>=0&&i<n&&j>=0&&j<n)return true;
    return false;
}
ll dx[8]={0,1,1,1,0,-1,-1,-1};
ll dy[8]={-1,-1,0,1,1,1,0,-1};

ll binarytodecimal(string n)
{
    string num = n;
    ll dec_value = 0;

   ll base = 1;

   ll len = num.length();
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}
string dtb(ll  n )
{
//    ,ll siz
    string s="";

    while(n>0){

    if(n%2==0)s.pb('0');
    else s.pb('1');
    n/=2;

    }

    reverse(all(s));
//       while(s.size()<siz)
//    {
//
//        s='0'+s;
//
//    }
    return s;
}

vec seive;
void Seive() {
    const ll maxn = 1e6 + 5;
    seive.resize(maxn);
    f(i,0, maxn) seive[i] = i;
    for(ll i=2;i<=maxn;i+=2)
    seive[i] = 2;
    seive[1] = -1;
    seive[0] = -1;
    for (ll i = 3; i <= maxn; i += 2)
        if (i == seive[i])
        for (ll j = i * i ; j < maxn ; j += i)
        if (seive[j] == j)
        seive[j] = i;
}
// ain't afraid of rating

int main()
{
fast;
ll n;
cin>>n;
string s;
vector<string> v;
map<string ,ll>mp,mp2;
vector<string> m[10];
f(k,0,n)
{cin>>s;
v.pb(s);
f(i,1,10)
{
    f(j,0,9)
    {
       if(j+i<10){ string y=s.substr(j,i);
        mp[y]++;
        m[i].pb(y);}
    }
}
}
vector<string> ans;
f(k,0,n)
{
    f(i,1,10)
{
    ll z=0;
    f(j,0,9)
    {
        string y=v[k].substr(j,i);
        mp2[y]++;
    }
   fa(x,m[i])
   {
       //cout<<x<<MM;
      // if(x=="000")cout<<mp[x]<<MM<<mp2[x]<<"\n";//en;
       if(mp[x]==mp2[x]){ans.pb(x);z++;break;}
   }//en;
   mp2.clear();
   if(z)break;
}

}
fa(x,ans)cout<<x<<"\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265
#define pb push_back
#define en cout<<'\n'
#define vec vector<ll>
#define vecs vector<string>
#define pii pair<double,double>
#define VP vector< pii >
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x) ud __builtin_ctzll(x)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define mm " "
#define MM " "
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define INF (ll)(9e18)
#define Sort(v) sort(v.begin(),v.end())
#define test ll T;cin>>T;while(T--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())
 const ll MOD=1000000000+7;
const ll MOD1 = 998244353;
   ll mod(ll x){
        return (x%MOD + MOD)%MOD;
    }
    ll mul(ll a , ll b){
        return mod(mod(a)*mod(b));
    }
string itos(ll s)
{
string str=to_string(s);
return str;
}
ll stoi2(string s)
{
    ll a= atoi(s.c_str());
    return a;
}
ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

bool isSubSequence(string str1, string str2, int m, int n)
{

    if (m == 0) return true;
    if (n == 0) return false;

    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);

    return isSubSequence(str1, str2, m, n-1);
}

bool ispalindrome(ll len,string str)
{

    for(int i = 0; i < len/2; i++){
        if(str[i] != str[len-1-i]){
            return false;
        }
    }
    return true;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll isprime(ll N){
    if(N<2 || (!(N&1) && N!=2))
        return 0;
    for(ll i=3; i*i<=N; i+=2){
        if(!(N%i))
            return 0;
    }
    return 1;
}
vec factor;
void factors(ll n)
{

for(ll i=1;i<=sqrt(n);i++)
{
    if(n%i==0)
    {
        if(i==n/i)
        factor.pb(i);
        else
        {
            factor.pb(i);
            factor.pb(n/i);
        }

    }
}

sort(all(factor));
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
	return (a/gcd(a,b))*b;
}
bool isvalid(ll i,ll j,ll n)
{
    if(i>=0&&i<n&&j>=0&&j<n)return true;
    return false;
}
ll dx[8]={0,1,1,1,0,-1,-1,-1};
ll dy[8]={-1,-1,0,1,1,1,0,-1};

ll binarytodecimal(string n)
{
    string num = n;
    ll dec_value = 0;

   ll base = 1;

   ll len = num.length();
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}
string dtb(ll  n )
{
//    ,ll siz
    string s="";

    while(n>0){

    if(n%2==0)s.pb('0');
    else s.pb('1');
    n/=2;

    }

    reverse(all(s));
//       while(s.size()<siz)
//    {
//
//        s='0'+s;
//
//    }
    return s;
}

vec seive;
void Seive() {
    const ll maxn = 1e6 + 5;
    seive.resize(maxn);
    f(i,0, maxn) seive[i] = i;
    for(ll i=2;i<=maxn;i+=2)
    seive[i] = 2;
    seive[1] = -1;
    seive[0] = -1;
    for (ll i = 3; i <= maxn; i += 2)
        if (i == seive[i])
        for (ll j = i * i ; j < maxn ; j += i)
        if (seive[j] == j)
        seive[j] = i;
}
// ain't afraid of rating

int main()
{
fast;
ll n;
cin>>n;
string s;
vector<string> v;
map<string ,ll>mp,mp2;
vector<string> m[n];
f(k,0,n)
{cin>>s;
v.pb(s);
f(i,1,10)
{
    f(j,0,9)
    {
       if(j+i<10){ string y=s.substr(j,i);
        mp[y]++;
        m[k].pb(y);}
    }
}
}
vector<string> ans;
f(k,0,n)
{mp2.clear();
fa(x,m[k])
{
    mp2[x]++;
}
fa(x,m[k])
{
    if(mp[x]==mp2[x]){ans.pb(x);break;}
}

}

fa(x,ans)cout<<x<<"\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265
#define pb push_back
#define en cout<<'\n'
#define vec vector<ll>
#define vecs vector<string>
#define pii pair<double,double>
#define VP vector< pii >
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x) ud __builtin_ctzll(x)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define mm " "
#define MM " "
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define INF (ll)(9e18)
#define Sort(v) sort(v.begin(),v.end())
#define test ll T;cin>>T;while(T--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())
 const ll MOD=1000000000+7;
const ll MOD1 = 998244353;
   ll mod(ll x){
        return (x%MOD + MOD)%MOD;
    }
    ll mul(ll a , ll b){
        return mod(mod(a)*mod(b));
    }
string itos(ll s)
{
string str=to_string(s);
return str;
}
ll stoi2(string s)
{
    ll a= atoi(s.c_str());
    return a;
}
ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

bool isSubSequence(string str1, string str2, int m, int n)
{

    if (m == 0) return true;
    if (n == 0) return false;

    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);

    return isSubSequence(str1, str2, m, n-1);
}

bool ispalindrome(ll len,string str)
{

    for(int i = 0; i < len/2; i++){
        if(str[i] != str[len-1-i]){
            return false;
        }
    }
    return true;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll isprime(ll N){
    if(N<2 || (!(N&1) && N!=2))
        return 0;
    for(ll i=3; i*i<=N; i+=2){
        if(!(N%i))
            return 0;
    }
    return 1;
}
vec factor;
void factors(ll n)
{

for(ll i=1;i<=sqrt(n);i++)
{
    if(n%i==0)
    {
        if(i==n/i)
        factor.pb(i);
        else
        {
            factor.pb(i);
            factor.pb(n/i);
        }

    }
}

sort(all(factor));
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
	return (a/gcd(a,b))*b;
}
bool isvalid(ll i,ll j,ll n)
{
    if(i>=0&&i<n&&j>=0&&j<n)return true;
    return false;
}
ll dx[8]={0,1,1,1,0,-1,-1,-1};
ll dy[8]={-1,-1,0,1,1,1,0,-1};

ll binarytodecimal(string n)
{
    string num = n;
    ll dec_value = 0;

   ll base = 1;

   ll len = num.length();
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}
string dtb(ll  n )
{
//    ,ll siz
    string s="";

    while(n>0){

    if(n%2==0)s.pb('0');
    else s.pb('1');
    n/=2;

    }

    reverse(all(s));
//       while(s.size()<siz)
//    {
//
//        s='0'+s;
//
//    }
    return s;
}

vec seive;
void Seive() {
    const ll maxn = 1e6 + 5;
    seive.resize(maxn);
    f(i,0, maxn) seive[i] = i;
    for(ll i=2;i<=maxn;i+=2)
    seive[i] = 2;
    seive[1] = -1;
    seive[0] = -1;
    for (ll i = 3; i <= maxn; i += 2)
        if (i == seive[i])
        for (ll j = i * i ; j < maxn ; j += i)
        if (seive[j] == j)
        seive[j] = i;
}
// ain't afraid of rating

int main()
{
fast;
ll n;
cin>>n;
string s;
vector<string> v;
map<string ,ll>mp,mp2;
vector<string> m[10];
f(k,0,n)
{cin>>s;
v.pb(s);
f(i,1,10)
{
    f(j,0,9)
    {
       if(j+i<10){ string y=s.substr(j,i);
        mp[y]++;
        m[k].pb(y);}
    }
}
}
vector<string> ans;
f(k,0,n)
{mp2.clear();
fa(x,m[k])
{
    mp2[x]++;
}
fa(x,m[k])
{
    if(mp[x]==mp2[x]){ans.pb(x);break;}
}

}

fa(x,ans)cout<<x<<"\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265
#define pb push_back
#define en cout<<'\n'
#define vec vector<ll>
#define vecs vector<string>
#define pii pair<double,double>
#define VP vector< pii >
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x) ud __builtin_ctzll(x)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define mm " "
#define MM " "
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define INF (ll)(9e18)
#define Sort(v) sort(v.begin(),v.end())
#define test ll T;cin>>T;while(T--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())
 const ll MOD=1000000000+7;
const ll MOD1 = 998244353;
   ll mod(ll x){
        return (x%MOD + MOD)%MOD;
    }
    ll mul(ll a , ll b){
        return mod(mod(a)*mod(b));
    }
string itos(ll s)
{
string str=to_string(s);
return str;
}
ll stoi2(string s)
{
    ll a= atoi(s.c_str());
    return a;
}
ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

bool isSubSequence(string str1, string str2, int m, int n)
{

    if (m == 0) return true;
    if (n == 0) return false;

    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);

    return isSubSequence(str1, str2, m, n-1);
}

bool ispalindrome(ll len,string str)
{

    for(int i = 0; i < len/2; i++){
        if(str[i] != str[len-1-i]){
            return false;
        }
    }
    return true;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll isprime(ll N){
    if(N<2 || (!(N&1) && N!=2))
        return 0;
    for(ll i=3; i*i<=N; i+=2){
        if(!(N%i))
            return 0;
    }
    return 1;
}
vec factor;
void factors(ll n)
{

for(ll i=1;i<=sqrt(n);i++)
{
    if(n%i==0)
    {
        if(i==n/i)
        factor.pb(i);
        else
        {
            factor.pb(i);
            factor.pb(n/i);
        }

    }
}

sort(all(factor));
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
	return (a/gcd(a,b))*b;
}
bool isvalid(ll i,ll j,ll n)
{
    if(i>=0&&i<n&&j>=0&&j<n)return true;
    return false;
}
ll dx[8]={0,1,1,1,0,-1,-1,-1};
ll dy[8]={-1,-1,0,1,1,1,0,-1};

ll binarytodecimal(string n)
{
    string num = n;
    ll dec_value = 0;

   ll base = 1;

   ll len = num.length();
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}
string dtb(ll  n )
{
//    ,ll siz
    string s="";

    while(n>0){

    if(n%2==0)s.pb('0');
    else s.pb('1');
    n/=2;

    }

    reverse(all(s));
//       while(s.size()<siz)
//    {
//
//        s='0'+s;
//
//    }
    return s;
}

vec seive;
void Seive() {
    const ll maxn = 1e6 + 5;
    seive.resize(maxn);
    f(i,0, maxn) seive[i] = i;
    for(ll i=2;i<=maxn;i+=2)
    seive[i] = 2;
    seive[1] = -1;
    seive[0] = -1;
    for (ll i = 3; i <= maxn; i += 2)
        if (i == seive[i])
        for (ll j = i * i ; j < maxn ; j += i)
        if (seive[j] == j)
        seive[j] = i;
}
// ain't afraid of rating

int main()
{
fast;
ll n;
cin>>n;
string s;
vector<string> v;
map<string ,ll>mp,mp2;
vector<string> m[10];
f(i,0,n)
{cin>>s;
v.pb(s);
f(i,1,10)
{
    f(j,0,9)
    {
       if(j+i<10){ string y=s.substr(j,i);
        mp[y]++;
        m[i].pb(y);}
    }
}
}
vector<string> ans;
f(k,0,n)
{
    f(i,1,10)
{
    ll z=0;
    f(j,0,9)
    {
        string y=v[k].substr(j,i);
        mp2[y]++;
    }
   fa(x,m[i])
   {
       //cout<<x<<MM;
      // if(x=="000")cout<<mp[x]<<MM<<mp2[x]<<"\n";//en;
       if(mp[x]==mp2[x]){ans.pb(x);z++;break;}
   }//en;
   mp2.clear();
   if(z)break;
}

}
fa(x,ans)cout<<x<<"\n";

}


#include <fstream>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
int n;
string s;
map<int, string> list;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		list[i] = s;
	}
	for (int i = 0; i < n; ++i) {
		string s1 = list[i];
		string sub = "";
		bool fin = false;
		for (int d = 1; d <= 9; ++d) { //длина подстроки
			if (fin) break;
			for (int k = 0; k + d-1 < 9; ++k) { //стартовая позиция
				fin = true;
				sub = s1.substr(k, d); //подстрока
				//cout << s1 << " : " << sub << " : (" << k << "; " << k+d << ")" << endl;
				for (int j = 0; j < n; ++j) { //перебираем остальные строки
					if (i != j) {
						string s2 = list[j]; //извлекаем
						string::size_type pos = s2.find(sub);
						if (pos != string::npos) { //если нашли, то эта подстрока не подходит
							fin = false;
							break;
						}
					}
				}
				if (fin) {
					cout << sub << endl;
					break;
				}
			}
		}
	}
//	system("pause");
	return 0;
}


#include <fstream>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
int n;
string s;
map<int, string> list;
map<string, int> wrong;
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> s;
		list[i] = s;
	}

	for (int i = 1; i <= n; ++i) {
		string s1 = list[i];
		for (int d = 1; d <= 9; ++d) {
			for (int k = 0; k + d <= 9; ++k) {
				string sub = s1.substr(k, d);
				if (wrong[sub] == 0 || wrong[sub] == i) wrong[sub] = i;
				else wrong[sub] = -1;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		string s1 = list[i];
		bool fin = false;
		for (int d = 1; d <= 9; ++d) {
			if (fin) break;
			for (int k = 0; k + d <= 9; ++k) {
				string sub = s1.substr(k, d);
				if (wrong[sub] == i) {
					for (char ch : sub) {
						printf("%c", ch);
					}
					printf("\n");
					fin = true;
					break;
				}
			}
		}
	}

//	system("pause");
	return 0;
}


#include <fstream>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
int n;
string s;
map<int, string> list;
map<string, int> wrong;
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> s;
		list[i] = s;
	}

	for (int i = 1; i <= n; ++i) {
		string s1 = list[i];
		for (int d = 1; d <= 9; ++d) {
			for (int k = 0; k + d <= 9; ++k) {
				string sub = s1.substr(k, d);
				if (wrong[sub] == 0 || wrong[sub] == i) wrong[sub] = i;
				else wrong[sub] = -1;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		string s1 = list[i];
		bool fin = false;
		for (int d = 1; d <= 9; ++d) {
			if (fin) break;
			for (int k = 0; k + d <= 9; ++k) {
				string sub = s1.substr(k, d);
				if (wrong[sub] == i) {
					cout << sub << endl;
					fin = true;
					break;
				}
			}
		}
	}

//	system("pause");
	return 0;
}


#include <fstream>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
int n;
string s;
map<int, string> list;
map<string, pair<char,int>> wrong;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		list[i] = s;
	}
	for (int i = 0; i < n; ++i) {
		string s1 = list[i];
		string sub = "";
		bool fin = false;
		for (int d = 1; d <= 9; ++d) { //длина подстроки
			if (fin) break;
			for (int k = 0; k + d-1 < 9; ++k) { //стартовая позиция
				fin = true;
				sub = s1.substr(k, d); //подстрока

				//cout << s1 << " : " << sub << " : (" << k << "; " << k + d << ")" << endl;
				if (wrong[sub].second == true && (wrong[sub].first == -1 || wrong[sub].first != i)) { //пропускаем, если подстрока уже встречалась либо в > 1 строках, либо не в этой
					fin = false;
					continue;
				}

				for (int j = 0; j < n; ++j) { //перебираем остальные строки
					if (i != j) {
						string s2 = list[j]; //извлекаем
						string::size_type pos = s2.find(sub);
						if (pos != string::npos) { //если нашли, то эта подстрока не подходит
							fin = false;
							if (wrong[sub].second == true) wrong[sub] = { -1, true };
							else wrong[sub] = {j, true};
							//break;
						}
					}
				}
				if (fin) {
					cout << sub << endl;
					break;
				}
			}
		}
	}
	//system("pause");
	return 0;
}


//声起立华乐独奏，曲末音无心结弦。
//I think the players who have done all the bad things here are those who have rotted to the bone in the real world.
//The journey of the future is so far away, but the light we can see is so rare. Even so, I still haven't given up hope completely.
//No matter what kind of memory, it's the life we lived.
//I can do anything as long as I have you.
//People can only see what they want to see and hear what they want to hear, and I am no exception.
//No matter what you see in the past, please don't lose yourself. No matter what you become, I am your companion.
//Like the night sky, wrap the sad world gently.
//Because we are born with nothing, we can have everything.
//Even if you forget me, I will not forget you.
//Even if it's only one in six billion, we'll still meet.
//You will no longer be a prop, but a person as his name.
//No matter what the final result is, as long as this is the path of your choice.
#include <bits/stdc++.h>
using namespace std; const int N=80001;
map<string,int> Q; int n;
string p[N];
inline int read()
{
	int s=0,w=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>p[i];
		for(int j=1;j<=9;j++) for(int k=0;j+k<=9;k++)
		{
			int &w=Q[p[i].substr(k,j)];
			w=w==0||w==i?i:-1;
		}
	}
	for(auto &u:Q)
	{
		int it=u.second;
		if(it&&p[it].size()>u.first.size()) p[it]=u.first;
	}
	for(int i=1;i<=n;i++) cout<<p[i]<<endl;
	return 0;
}


//声起立华乐独奏，曲末音无心结弦。
//I think the players who have done all the bad things here are those who have rotted to the bone in the real world.
//The journey of the future is so far away, but the light we can see is so rare. Even so, I still haven't given up hope completely.
//No matter what kind of memory, it's the life we lived.
//I can do anything as long as I have you.
//People can only see what they want to see and hear what they want to hear, and I am no exception.
//No matter what you see in the past, please don't lose yourself. No matter what you become, I am your companion.
//Like the night sky, wrap the sad world gently.
//Because we are born with nothing, we can have everything.
//Even if you forget me, I will not forget you.
//Even if it's only one in six billion, we'll still meet.
//You will no longer be a prop, but a person as his name.
//No matter what the final result is, as long as this is the path of your choice.
#include <bits/stdc++.h>
using namespace std; const int N=80001;
unordered_map<string,int> Q; int n;
string p[N];
inline int read()
{
	int s=0,w=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>p[i];
		for(int j=1;j<=9;j++) for(int k=0;j+k<=9;k++)
		{
			int &w=Q[p[i].substr(k,j)];
			w=w==0||w==i?i:-1;
		}
	}
	for(auto &u:Q)
	{
		int it=u.second;
		if(it>0&&p[it].size()>u.first.size()) p[it]=u.first;
	}
	for(int i=1;i<=n;i++) cout<<p[i]<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define int long long
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif

	int n;
	cin >> n;
	vector<string> vec(n);
	map<string, int> mp;
	for(int k = 0; k < n; ++ k)
	{
		cin >> vec[k];
		int len = vec[k].size();
		set<string> done;
		for(int i = 0; i < len; ++ i)
		{
			for(int j = i; j < len; ++ j)
			{
				string cur = vec[k].substr(i, j - i + 1);
				if(!done.count(cur))
				{
					++ mp[vec[k].substr(i, j - i + 1)];
					done.insert(cur);
				}
			}
		}
	}
	debug(mp);
	for(int k = 0; k < n; ++ k)
	{
		int mn = 1e17;
		string mnval;
		int len = vec[k].size();
		for(int i = 0; i < len; ++ i)
		{
			for(int j = i; j < len; ++ j)
			{
				if(mp[vec[k].substr(i, j - i + 1)] == 1)
				{
					if(j - i + 1 < mn)
					{
						mn = j - i + 1;
						mnval = vec[k].substr(i, j - i + 1);
					}
				}
			}
		}
		cout << mnval << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define int long long
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif

	int n;
	cin >> n;
	vector<string> vec(n);
	map<string, int> mp;
	for(int k = 0; k < n; ++ k)
	{
		cin >> vec[k];
		int len = vec[k].size();
		for(int i = 0; i < len; ++ i)
		{
			for(int j = i; j < len; ++ j)
			{
				++ mp[vec[k].substr(i, j - i + 1)];
			}
		}
	}
	debug(mp);
	for(int k = 0; k < n; ++ k)
	{
		int mn = 1e17;
		string mnval;
		int len = vec[k].size();
		for(int i = 0; i < len; ++ i)
		{
			for(int j = i; j < len; ++ j)
			{
				if(mp[vec[k].substr(i, j - i + 1)] == 1)
				{
					if(j - i + 1 < mn)
					{
						mn = j - i + 1;
						mnval = vec[k].substr(i, j - i + 1);
					}
				}
			}
		}
		cout << mnval << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define int long long
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif

	int n;
	cin >> n;
	vector<string> vec(n);
	map<string, set<int>> mp;
	for(int k = 0; k < n; ++ k)
	{
		cin >> vec[k];
		int len = vec[k].size();
		for(int i = 0; i < len; ++ i)
		{
			for(int j = i; j < len; ++ j)
			{
				mp[vec[k].substr(i, j - i + 1)].insert(k);
			}
		}
	}
	debug(mp);
	for(int k = 0; k < n; ++ k)
	{
		int mn = 1e17;
		string mnval;
		int len = vec[k].size();
		for(int i = 0; i < len; ++ i)
		{
			for(int j = i; j < len; ++ j)
			{
				if(mp[vec[k].substr(i, j - i + 1)].size() == 1)
				{
					if(j - i + 1 < mn)
					{
						mn = j - i + 1;
						mnval = vec[k].substr(i, j - i + 1);
					}
				}
			}
		}
		cout << mnval << '\n';
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back

using namespace std;

struct TrieNode{
    TrieNode *children[10];
    ll IsEndOfWord=0;
    int ind=0;
};

TrieNode *getnode(){
    TrieNode *node=new TrieNode;
    for(auto &child:node->children){
        child=nullptr;
    }
    return node;
}

void add(TrieNode *root,string &s,int i){
    TrieNode *cur_node=root;
    for(auto c:s){
        int ind=c-'0';
        if(cur_node->children[ind]==nullptr)cur_node->children[ind]=getnode();
        cur_node=cur_node->children[ind];
        if(cur_node->ind!=i){
            cur_node->IsEndOfWord++;
            cur_node->ind=i;
        }
    }

}

ll search(TrieNode *root,string &s){
    TrieNode *cur_node=root;
    ll dp=0;
    for(auto c:s){
        int ind=c-'0';
        dp++;
        cur_node=cur_node->children[ind];
        if(cur_node->IsEndOfWord==1){
            return dp;
        }
    }
    return INT_MAX;
}

void solve(){
    int n;cin>>n;
    string s[n+1];
    TrieNode *root=getnode();
    for(int i=1;i<=n;i++){
        cin>>s[i];
        for(int k=0;k<9;k++){
            string s1="";
            for(int j=k;j<9;j++){
                s1+=s[i][j];
            }
            add(root,s1,i);
        }
    }
    for(int i=1;i<=n;i++){
        ll mn=INT_MAX;
        string ans="";
        for(int k=0;k<9;k++){
                string s1="";
            for(int j=k;j<9;j++)s1+=s[i][j];
            int len=search(root,s1);
            if(len<mn){
                    ans="";
                for(int j=k;j<k+len;j++)ans+=s[i][j];
            }

        }
        cout<<ans<<"\n";
    }
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define epb emplace_back
#define f first
#define s second
using namespace std;

struct TrieNode{
    TrieNode *children[10];
    int IsEndOfWord=0;
    int ind=0;
};

TrieNode *getnode(){
    TrieNode *node=new TrieNode;
    for(auto &child:node->children)child=nullptr;
    return node;
}

void add(TrieNode *root,string &s,int i){
    TrieNode *cur_node=root;
    for(auto c:s){
        int ind=c-'0';
        if(cur_node->children[ind]==nullptr)cur_node->children[ind]=getnode();
        cur_node=cur_node->children[ind];
    }
    if(cur_node->ind!=i)
    cur_node->IsEndOfWord++,cur_node->ind=i;
}

bool search(TrieNode *root,string &s){
    TrieNode *cur_node=root;
    for(auto c:s){
        int ind=c-'0';
        cur_node=cur_node->children[ind];
    }
    return cur_node->IsEndOfWord<2;
}

void solve(){
    int n;cin>>n;
    string s[n+1];
    TrieNode *root=getnode();
    for(int i=1;i<=n;i++){
        cin>>s[i];
        for(int k=0;k<9;k++){
            string s1="";

            for(int j=k;j<9;j++){
                s1+=s[i][j];

                add(root,s1,i);
            }
        }
    }
    for(int i=1;i<=n;i++){
        int mn=INT_MAX;
        string ans;
        for(int k=0;k<9;k++){
            string s1="";

            for(int j=k;j<9;j++){
                s1+=s[i][j];
                if(search(root,s1)&&mn>(int)s1.size()){
                    ans=s1;
                    mn=(int)s1.size();

                }
            }
        }
        cout<<ans<<"\n";
    }

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back

using namespace std;

struct TrieNode{
    TrieNode *children[10];
    ll IsEndOfWord=0;
    int ind=0;
};

TrieNode *getnode(){
    TrieNode *node=new TrieNode;
    for(auto &child:node->children){
        child=nullptr;
    }
    return node;
}

void add(TrieNode *root,string &s,int i){
    TrieNode *cur_node=root;
    for(auto c:s){
        int ind=c-'0';
        if(cur_node->children[ind]==nullptr)cur_node->children[ind]=getnode();
        cur_node=cur_node->children[ind];
        if(cur_node->ind!=i){
            cur_node->IsEndOfWord++;
            cur_node->ind=i;
        }
    }

}

ll search(TrieNode *root,string &s){
    TrieNode *cur_node=root;
    ll dp=0;
    for(auto c:s){
        int ind=c-'0';
        dp++;
        cur_node=cur_node->children[ind];
        if(cur_node->IsEndOfWord==1){
            return dp;
        }
    }
    return INT_MAX;
}

void solve(){
    int n;cin>>n;
    string s[n+1];
    TrieNode *root=getnode();
    for(int i=1;i<=n;i++){
        cin>>s[i];
        for(int k=0;k<9;k++){
            string s1="";
            for(int j=k;j<9;j++){
                s1+=s[i][j];
            }
            add(root,s1,i);
        }
    }
    for(int i=1;i<=n;i++){
        ll mn=INT_MAX;
        string ans="";
        for(int k=0;k<9;k++){
                string s1="";
            for(int j=k;j<9;j++)s1+=s[i][j];
            int len=search(root,s1);
            if(len<mn){
                ans="";
                for(int j=k;j<k+len;j++)ans+=s[i][j];
                mn=len;
            }

        }
        cout<<ans<<"\n";
    }
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}


#include<iostream>
#include<iomanip>
#include<queue>
#include<cmath>
#include<algorithm>
#include<set>
#include<cassert>
#include<map>
#include<cstring>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const int max_n = 70000 + 1;
#define mp(a,b) make_pair(a,b)
#define f first
#define s second
#define forn(i,n) for(ll i=0; i<(ll)n; i++)
#define pb(a) push_back(a)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

int n;
string pn[max_n];
map<string,set<int>>mp;
int main()
{
	ios;
	cin >> n;
	for (int i = 0; i < n; i++)		cin >> pn[i];

	for (int k = 0; k < n; k++)
		for (int i = 0; i < 9; i++)
			for (int j = i; j < 9; j++)
				mp[pn[k].substr(i, j - i + 1)].insert(k);

 	for (int k = 0; k < n; k++)
	{
		int mini = 10;
		string ans;
		for(int i=0; i<9; i++)
			for (int j = i; j < 9; j++)
			{
				int cnt = mp[pn[k].substr(i, j - i + 1)].size();

				if (cnt == 1)
				{
					if (mini > j - i + 1)
					{
						mini = j - i + 1;
						ans = pn[k].substr(i, j-i+1);
					}
				}
			}
		cout << ans<<"\n";
	}
}


#include<iostream>
#include<iomanip>
#include<queue>
#include<cmath>
#include<algorithm>
#include<set>
#include<cassert>
#include<map>
#include<cstring>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const int max_n = 70000 + 1;
#define mp(a,b) make_pair(a,b)
#define f first
#define s second
#define forn(i,n) for(ll i=0; i<(ll)n; i++)
#define pb(a) push_back(a)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

int n;
string pn[max_n];
map<string,int>mp;

int main()
{
	ios;
	cin >> n;
	for (int i = 0; i < n; i++)		cin >> pn[i];

	for (int k = 0; k < n; k++)
	{
		set<string>st;

		for (int i = 0; i < 9; i++)
			for (int j = i; j < 9; j++)
				st.insert(pn[k].substr(i, j - i + 1));

		for (auto it : st)
			mp[it]++;
	}

 	for (int k = 0; k < n; k++)
	{
		int mini = 10;
		string ans;
		for (int i = 0; i < 9; i++)
		{
			for (int j = i; j < 9; j++)
			{
				int cnt = mp[pn[k].substr(i, j - i + 1)];
				if (cnt == 1)
				{
					if (mini > j - i + 1)
					{
						mini = j - i + 1;
						ans = pn[k].substr(i, j - i + 1);
					}
				}
			}
			if (mini == 1)
				break;
		}
		cout << ans<<"\n";
	}
}


/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif

void solve() {
	int n;
	cin >> n;
	unordered_map<string,int> cnt;
	vector<string> arr(n);
	string s;
	const int N = 9;
	for(int i = 0; i < n; i++){
		cin >> s;
		arr[i] = s;
		set<string> cur;
		for(int j = 0; j < N; j++){
			for(int k = j; k < N; k++){
				cur.insert(s.substr(j, k-j+1));
			}
		}
		for(auto &str: cur){
			cnt[str]++;
		}
	}
	for(int i = 0; i < n; i++){
		bool found = false;
		for(int len = 1; len <= N && !found; len++){
			for(int j = 0; j <= N-len && !found; j++){
				if(cnt[arr[i].substr(j, len)] == 1){
					cout << arr[i].substr(j, len) << '\n';
					found = true;
				}
			}
		}
		assert(found);
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef SHUBHAM107
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}


/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif

void solve() {
	int n;
	cin >> n;
	map<string,int> cnt;
	vector<string> arr(n);
	string s;
	const int N = 9;
	for(int i = 0; i < n; i++){
		cin >> s;
		arr[i] = s;
		set<string> cur;
		for(int j = 0; j < N; j++){
			for(int k = j; k < N; k++){
				cur.insert(s.substr(j, k-j+1));
			}
		}
		for(auto &str: cur){
			cnt[str]++;
		}
	}
	for(int i = 0; i < n; i++){
		bool found = false;
		for(int len = 1; len <= N && !found; len++){
			for(int j = 0; j <= N-len && !found; j++){
				if(cnt[arr[i].substr(j, len)] == 1){
					cout << arr[i].substr(j, len) << '\n';
					found = true;
				}
			}
		}
		assert(found);
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef SHUBHAM107
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}


#include<bits/stdc++.h>
#define pp push_back
using namespace std;

int n, flag[1000000];
string s[70009];
vector<vector<int>>v;

void insert(string s, int idx) {
	int cur = 0;
	for (int i = 0; i < s.size(); ++i) {
		int j = s[i] - '0';

		if (v[cur][j] == -1) {
			v[cur][j] = v.size();
			v.pp(vector<int>(10, -1));
		}
		cur = v[cur][j];
		if (!flag[cur])flag[cur] = idx;
		else if (flag[cur] != idx)flag[cur] = -1;
	}
}
bool uni(const string &s) {
	int cur = 0;
	for (int i = 0; i < s.size(); ++i) {
		int j = s[i] - '0';
		cur = v[cur][j];
	}
	return (flag[cur] != -1);
}
string mn(int idx) {
	for (int i = 1; i <= 9; ++i)
		for (int j = 0; j + i - 1 < 9; ++j) {
			string t = s[idx].substr(j, i);
			if (uni(t))return t;
		}
	return "-";
}
int main() {
	//	ios_base::sync_with_stdio(0); cin.tie(NULL);
	v.pp(vector<int>(10, -1));

	//Scan & build
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		for (int j = 0; j < 9; ++j)
			insert(s[i].substr(j, 9 - j), i + 1);
	}

	//Print
	for (int i = 0; i < n; ++i)
		cout << mn(i) << endl;
	return 0;
}


#include<bits/stdc++.h>
#define pp push_back
using namespace std;

int n, flag[1000000], start, endd;
char C[12];
string s[70009];
vector<vector<int>>v;

void insert(string s, int idx) {
	int cur = 0;
	for (int i = 0; i < s.size(); ++i) {
		int j = s[i] - '0';

		if (v[cur][j] == -1) {
			v[cur][j] = v.size();
			v.pp(vector<int>(10, -1));
		}
		cur = v[cur][j];
		if (!flag[cur])flag[cur] = idx;
		else if (flag[cur] != idx)flag[cur] = -1;
	}
}
bool uni(const string &s) {
	int cur = 0;
	for (int i = 0; i < s.size(); ++i) {
		int j = s[i] - '0';
		cur = v[cur][j];
	}
	return (flag[cur] != -1);
}
void mn(int idx) {
	for (int i = 1; i <= 9; ++i)
		for (int j = 0; j + i - 1 < 9; ++j) {
			string t = s[idx].substr(j, i);
			if (uni(t)) {
				start = j, endd = j + i - 1;
				return;
			}
		}
}
int main() {
	v.pp(vector<int>(10, -1));

	//Scan & build
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%s", C), s[i] = C;
		for (int j = 0; j < 9; ++j)
			insert(s[i].substr(j, 9 - j), i + 1);
	}

	//Print
	for (int i = 0; i < n; ++i) {
		mn(i);
		while (start <= endd)printf("%c", s[i][start++]);
		puts("");
	}
	return 0;
}


/*
         --┬--  |     |  --┬--                |       |
           |    |\    |    |                  |       |
           |    | \   |    |     ----->       |       |
           |    |  \  |    |                  |       |
           |    |   \ |    |                  |       |
         --┴--  |    \|    |                  └----   └----

*/

#define pragma

#ifdef pragma
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif // pragma

#include<bits/stdc++.h>
#include<string>

#define ll long long
#define all(x) begin(x),end(x)
#define pb push_back
#define x first
#define y second
#define INF 9223372036854775807ll
#define PI 3.14159265359d
#define INPUT "input.txt"
#define OUTPUT "output.txt"
#define sz size
#define rsz resize
#define int long long

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef long double ld;
typedef vector<vi> matrix;

void seriy() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef _android
        freopen("input", "r", stdin);
        freopen("output", "w", stdout);
    #else
        //_android
    #endif
}

signed main(){
    seriy();
    int n;
    cin >> n;
    vector<set<string> > st(n);
    vector<map<string, int> > mp(n);
    map<string ,int> al;
    for(int i = 0; i < n; i++) {
        string a;
        cin >> a;
        for(int j = 0; j < 9; j++) {
            for(int k = 1; k < 9 - j + 1; k++) {
                st[i].insert(a.substr(j, k));
                mp[i][a.substr(j, k)]++;
                al[a.substr(j, k)]++;
            }
        }
    }
    vector<string> ans(n, "111111111111");
    for(int i = 0; i < n; i++) {
        for(auto j : st[i]) {
            if(al[j] - mp[i][j] == 0) {
                if(ans[i].size() > j.size()) {
                    ans[i] = j;
                }
            }
        }
    }
    for(auto i : ans) {
        cout << i << endl;
    }
    return 0;
}


/*
         --┬--  |     |  --┬--                |       |
           |    |\    |    |                  |       |
           |    | \   |    |     ----->       |       |
           |    |  \  |    |                  |       |
           |    |   \ |    |                  |       |
         --┴--  |    \|    |                  └----   └----

*/

#define pragma

#ifdef pragma
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif // pragma

#include<bits/stdc++.h>

#define ll long long
#define all(x) begin(x),end(x)
#define pb push_back
#define x first
#define y second
#define int long long

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef long double ld;
typedef vector<vi> matrix;

const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const ld EPS = 1e-9;
const ld PI = atan2(0, -1);

void seriy() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // cout << fixed << setprecision(6);
    #if _android
        freopen("input", "r", stdin);
        freopen("output", "w", stdout);
    #endif
}

struct pt {
    int x, y;
};

istream& operator>>(istream& is, pt& p) {
      is >> p.x >> p.y;
      return is;
}

ostream& operator<<(ostream& os, pt& p) {
      os << p.x << " " << p.y;
      return os;
}

signed main() {
    seriy();
    int n;
    cin >> n;
    map<string, set<int>> mp;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < s.length(); j++) {
            for(int k = 0; k < s.length() - j; k++) {
                mp[s.substr(k, j + 1)].insert(i);
            }
        }
    }
    vi ans(n, INF);
    vector<string> res(n);
    for(auto it = mp.begin(); it != mp.end(); it++) {
//        cout << it -> x << "    " << (it -> y).size();
//        cout << '\n';
        if((it -> y).size() == 1) {
            if(ans[*((it -> y).begin())] > (int)((it -> x).length())) {
                ans[*((it -> y).begin())] = (int)((it -> x).length());
                res[*((it -> y).begin())] = it -> x;
            }

        }
//        cout << '\n';
    }
    for(auto i : res) {
        cout << i << '\n';
    }
    return 0;
}


/*
         --┬--  |     |  --┬--                |       |
           |    |\    |    |                  |       |
           |    | \   |    |     ----->       |       |
           |    |  \  |    |                  |       |
           |    |   \ |    |                  |       |
         --┴--  |    \|    |                  └----   └----

*/

#define pragma

#ifdef pragma
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif // pragma

#include<bits/stdc++.h>
#include<string>

#define ll long long
#define all(x) begin(x),end(x)
#define pb push_back
#define x first
#define y second
#define INF 9223372036854775807ll
#define PI 3.14159265359d
#define INPUT "input.txt"
#define OUTPUT "output.txt"
#define sz size
#define rsz resize
#define int long long

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef long double ld;
typedef vector<vi> matrix;

void seriy() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef _android
        freopen("input", "r", stdin);
        freopen("output", "w", stdout);
    #else
        //_android
    #endif
}

signed main(){
    seriy();
    int n;
    cin >> n;
    vector<set<string> > st(n);
    vector<map<string, int> > mp(n);
    map<string ,int> al;
    for(int i = 0; i < n; i++) {
        string a;
        cin >> a;
        for(int j = 0; j < 9; j++) {
            for(int k = 1; k < 9 - j + 1; k++) {
                st[i].insert(a.substr(j, k));
                mp[i][a.substr(j, k)]++;
                al[a.substr(j, k)]++;
            }
        }
    }
    for(int i = 0; i < n; i++) {
        string ans = "111111111111";
        for(auto j : st[i]) {
            if(al[j] - mp[i][j] == 0) {
                if(ans.size() > j.size()) {
                    ans = j;
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


/*
         --┬--  |     |  --┬--                |       |
           |    |\    |    |                  |       |
           |    | \   |    |     ----->       |       |
           |    |  \  |    |                  |       |
           |    |   \ |    |                  |       |
         --┴--  |    \|    |                  └----   └----

*/

#define pragma

#ifdef pragma
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif // pragma

#include<bits/stdc++.h>
#include<string>

#define ll long long
#define all(x) begin(x),end(x)
#define pb push_back
#define x first
#define y second
#define INF 9223372036854775807ll
#define PI 3.14159265359d
#define INPUT "input.txt"
#define OUTPUT "output.txt"
#define sz size
#define rsz resize
#define int long long

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef long double ld;
typedef vector<vi> matrix;

void seriy() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef _android
        freopen("input", "r", stdin);
        freopen("output", "w", stdout);
    #else
        //_android
    #endif
}

signed main(){
    seriy();
    int n;
    cin >> n;
    vector<string> a(n);
    vector<set<string> > st(n);
    vector<map<string, int> > mp(n);
    map<string ,int> al;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 9; j++) {
            for(int k = 1; k < 9 - j + 1; k++) {
                st[i].insert(a[i].substr(j, k));
                mp[i][a[i].substr(j, k)]++;
                al[a[i].substr(j, k)]++;
            }
        }
    }
    vector<string> ans(n, "111111111111");
    for(int i = 0; i < n; i++) {
        for(auto j : st[i]) {
            if(al[j] - mp[i][j] == 0) {
                if(ans[i].size() > j.size()) {
                    ans[i] = j;
                }
            }
        }
    }
    for(auto i : ans) {
        cout << i << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=7e4+4;
int mx;
string ans;
struct Trie{
    int ch[maxn][10],val[maxn],sz;
    Trie()
    {
        memset(ch,0,sizeof ch);
        sz=1;
        memset(val,0,sizeof val);
    }
    void insert(string s)
    {
        int rt=0;
        for(int i=0;i<s.size();i++)
        {
            int id=s[i]-'0';
            if(!ch[rt][id])
            {
                ch[rt][id]=sz;
                val[sz]++;
                sz++;
            }
            else val[ch[rt][id]]++;
            rt=ch[rt][id];
        }
    }
    void del(string s)
    {
        int rt=0;
        for(int i=0;i<s.size();i++)
        {
            int id=s[i]-'0';
            if(!ch[rt][id]) return;
            rt=ch[rt][id];
            val[rt]--;
        }
    }
    void query(string s)
    {
        int rt=0;
        string tmp;
        for(int i=0;i<s.size();i++)
        {
            tmp+=s[i];
            int id=s[i]-'0';
            rt=ch[rt][id];
            if(!val[rt])
            {
                if(i+1<mx)
                {
                    mx=i+1;
                    ans=tmp;
                }
            }
        }
    }
}T;
string s[maxn];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        for(int j=0;j<9;j++)
            T.insert(s[i].substr(j,9-j));
    }
    for(int i=1;i<=n;i++)
    {
        mx=10;
        for(int j=0;j<9;j++)
            T.del(s[i].substr(j,9-j));
        for(int j=0;j<9;j++)
            T.query(s[i].substr(j,9-j));
        for(int j=0;j<9;j++)
            T.insert(s[i].substr(j,9-j));
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int mx;
string ans;
struct Trie{
    int ch[maxn][10],val[maxn],sz;
    Trie()
    {
        memset(ch,0,sizeof ch);
        sz=1;
        memset(val,0,sizeof val);
    }
    void insert(string s)
    {
        int rt=0;
        for(int i=0;i<s.size();i++)
        {
            int id=s[i]-'0';
            if(!ch[rt][id])
            {
                ch[rt][id]=sz;
                val[sz]++;
                sz++;
            }
            else val[ch[rt][id]]++;
            rt=ch[rt][id];
        }
    }
    void del(string s)
    {
        int rt=0;
        for(int i=0;i<s.size();i++)
        {
            int id=s[i]-'0';
            if(!ch[rt][id]) return;
            rt=ch[rt][id];
            val[rt]--;
        }
    }
    void query(string s)
    {
        int rt=0;
        string tmp;
        for(int i=0;i<s.size();i++)
        {
            tmp+=s[i];
            int id=s[i]-'0';
            rt=ch[rt][id];
            if(!val[rt])
            {
                if(i+1<mx)
                {
                    mx=i+1;
                    ans=tmp;
                    break;
                }
            }
        }
    }
}T;
string s[maxn];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        for(int j=0;j<9;j++)
            T.insert(s[i].substr(j,9-j));
    }
    for(int i=1;i<=n;i++)
    {
        mx=10;
        for(int j=0;j<9;j++)
            T.del(s[i].substr(j,9-j));
        for(int j=0;j<9;j++)
            T.query(s[i].substr(j,9-j));
        for(int j=0;j<9;j++)
            T.insert(s[i].substr(j,9-j));
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int mx;
string ans;
struct Trie{
    int ch[maxn][10],val[maxn],sz;
    Trie()
    {
        memset(ch,0,sizeof ch);
        sz=1;
        memset(val,0,sizeof val);
    }
    void insert(string s)
    {
        int rt=0;
        for(int i=0;i<s.size();i++)
        {
            int id=s[i]-'0';
            if(!ch[rt][id])
            {
                ch[rt][id]=sz;
                val[sz]++;
                sz++;
            }
            else val[ch[rt][id]]++;
            rt=ch[rt][id];
        }
    }
    void del(string s)
    {
        int rt=0;
        for(int i=0;i<s.size();i++)
        {
            int id=s[i]-'0';
            if(!ch[rt][id]) return;
            rt=ch[rt][id];
            val[rt]--;
        }
    }
    void query(string s)
    {
        int rt=0;
        string tmp;
        for(int i=0;i<s.size();i++)
        {
            tmp+=s[i];
            int id=s[i]-'0';
            rt=ch[rt][id];
            if(!val[rt])
            {
                if(i+1<mx)
                {
                    mx=i+1;
                    ans=tmp;
                }
            }
        }
    }
}T;
string s[maxn];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        for(int j=0;j<9;j++)
            T.insert(s[i].substr(j,9-j));
    }
    for(int i=1;i<=n;i++)
    {
        mx=10;
        for(int j=0;j<9;j++)
            T.del(s[i].substr(j,9-j));
        for(int j=0;j<9;j++)
            T.query(s[i].substr(j,9-j));
        for(int j=0;j<9;j++)
            T.insert(s[i].substr(j,9-j));
        cout<<ans<<endl;
    }
    return 0;
}


//============================================================================
// Name        : competitive_programing.cpp
// Author      : .Data_Nerd.
// Description : problem solving training
//============================================================================

#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 1000000007
#define OO 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

ll n;

vector <string> v;

unordered_map <string, ll> mp;

int main() {
    Data_Nerd

    cin >> n; v.resize(n);

    for(ll i = 0; i < n; ++i){
        cin >> v[i];
        unordered_map <string, ll> hereBef;
        for(ll j = 0; j < 9; ++j){
            string temp;
            for(ll k = j; k < 9; ++k){
                temp += v[i][k];
                if(!hereBef[temp]){
                    ++hereBef[temp], ++mp[temp];
                }
            }
        }
    }

    for(ll i = 0; i < n; ++i){
        string res = "";
        for(ll j = 0; j < 9; ++j){
            string temp;
            for(ll k = j; k < 9; ++k){
                temp += v[i][k];
                if(mp[temp] == 1){
                    if(!res.size())
                        res = temp;
                    else if(res.size() > temp.size())
                        res = temp;
                }
            }
        }
        cout << res << endl;
    }

    return 0;
}


//============================================================================
// Name        : competitive_programing.cpp
// Author      : .Data_Nerd.
// Description : problem solving training
//============================================================================

#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 1000000007
#define OO 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

ll n;

vector <string> v;

map <string, ll> mp;

int main() {
	Data_Nerd

	cin >> n; v.resize(n);

	for(ll i = 0; i < n; ++i){
		cin >> v[i];
		map <string, ll> hereBef;
		for(ll j = 0; j < 9; ++j){
			string temp;
			for(ll k = j; k < 9; ++k){
				temp += v[i][k];
				if(!hereBef[temp]){
					++hereBef[temp], ++mp[temp];
				}
			}
		}
	}

	for(ll i = 0; i < n; ++i){
		string res = "";
		for(ll j = 0; j < 9; ++j){
			string temp;
			for(ll k = j; k < 9; ++k){
				temp += v[i][k];
				if(mp[temp] == 1){
					if(!res.size())
						res = temp;
					else if(res.size() > temp.size())
						res = temp;
				}
			}
		}
		cout << res << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN (int)(2e5 + 5)
#define MAXM (int)(1e2+5)
#define fr first
#define sd second
#define MP make_pair
#define pb push_back
#define SZ(A) (int)A.size()
#define ALL(v) v.begin(), v.end()
#define M0(a) memset(a, 0, sizeof(a))
#define M1(a) memset(a, -1, sizeof(a))
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REPN(i,n,m) for(int i = m; i <= int(n); i++)
#define RREP(i,n) for(int i = int(n-1); i >= 0; i--)
#define RREPN(i, n, m) for(int i = n; i >= (int)m; i--)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const ll INF= ll(1e18 + 5);
const ll MOD = ll(1e9 + 9);
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> ppii;
template<typename T, typename U> inline void AMIN(T &x, U y){ if(x > y) x = y;}
template<typename T, typename U> inline void AMAX(T &x, U y){ if(x < y) x = y;}

void build(map<string, int> &MS, string S) {

        map<string, int> M;
        REP(i, S.size()) {

                string X;
                REPN(j, S.size() - 1, i) {

                        X += S[j];
                        if(!M[X])
                                M[X] = 1, MS[X]++;
                }
        }
}

void REM(map<string, int> &MS, string S) {

        REP(i, S.size()) {

                string X;
                REPN(j, S.size() - 1, i) {

                        X += S[j];
                        MS[X]--;
                }
        }
}

string GA(map<string, int> &MS, string S) {

        int len = INT_MAX;
        string ans;
        REP(i, S.size()) {

                string X = "";
                REPN(j, S.size() - 1, i) {

                        X += S[j];
                        if(MS[X] == 1 && X.size() < len)
                                ans = X, len = X.size();
                }
        }
        return ans;
}

int main() {

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int N;
        cin >> N;

        vector<string> VS;
        map<string, int> MS;
        REP(i, N) {

                string S;
                cin >> S;
                VS.pb(S);
                build(MS, S);
        }

        REP(i, N) {

                string S = VS[i];
                cout << GA(MS, S) << endl;
        }
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN (int)(2e5 + 5)
#define MAXM (int)(1e2+5)
#define fr first
#define sd second
#define MP make_pair
#define pb push_back
#define SZ(A) (int)A.size()
#define ALL(v) v.begin(), v.end()
#define M0(a) memset(a, 0, sizeof(a))
#define M1(a) memset(a, -1, sizeof(a))
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REPN(i,n,m) for(int i = m; i <= int(n); i++)
#define RREP(i,n) for(int i = int(n-1); i >= 0; i--)
#define RREPN(i, n, m) for(int i = n; i >= (int)m; i--)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const ll INF= ll(1e18 + 5);
const ll MOD = ll(1e9 + 9);
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> ppii;
template<typename T, typename U> inline void AMIN(T &x, U y){ if(x > y) x = y;}
template<typename T, typename U> inline void AMAX(T &x, U y){ if(x < y) x = y;}

void build(map<string, int> &MS, string S) {

        REP(i, S.size()) {

                string X;
                REPN(j, S.size() - 1, i) {

                        X += S[j];
                        MS[X]++;
                }
        }
}

void REM(map<string, int> &MS, string S) {

        REP(i, S.size()) {

                string X;
                REPN(j, S.size() - 1, i) {

                        X += S[j];
                        MS[X]--;
                }
        }
}

string GA(map<string, int> &MS, string S) {

        int len = INT_MAX;
        string ans;
        REP(i, S.size()) {

                string X;
                REPN(j, S.size() - 1, i) {

                        X += S[j];
                        if(!MS[X] && X.size() < len)
                                ans = X, len = X.size();
                }
        }
        return ans;
}

int main() {

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int N;
        cin >> N;

        vector<string> VS;
        map<string, int> MS;
        REP(i, N) {

                string S;
                cin >> S;
                VS.pb(S);
                build(MS, S);
        }

        REP(i, N) {

                string S = VS[i];
                REM(MS, S);

                cout << GA(MS, S) << endl;
                build(MS, S);
        }
        return 0;
}


#include <bits/stdc++.h>

#define INF 1000000001
#define LINF 1000000000000000001LL
#define ll long long
#define ld long double
#define M 1000000007
#define N (1<<20)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second

using namespace std;

vector<pii> v[N][2];
vector<int> ms;
bitset<N> e[2];

void dfs (int i, int x) {
	if (e[x][i]) return;
	e[x][i] = 1;
	for (pii p : v[i][x]) {
		dfs(p.F, p.S);
	}
}

int main () {
	cin.sync_with_stdio(false);
	cin.tie(0);

	int n;
	int m;
	cin>>n>>m;
	for (int i = 1; i <= m; i++) {
		int x;
		cin>>x;
		ms.push_back(x);
	}
	sort(ms.begin(), ms.end());
	for (int i : ms) {
		v[i][0].push_back({i, 1});
		v[(1<<n) - 1 - i][1].push_back({i, 0});
	}
	for (int i = 0; i < (1<<n); i++) {
		for (int j = 0; j < n; j++) {
			v[i][1].push_back({i | (1<<j), 1});
		}
	}
	int ans = 0;
	for (int i : ms) {
		if (!e[0][i]) {
			ans++;
			dfs(i, 0);
		}
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>

#define INF 1000000001
#define LINF 1000000000000000001LL
#define ll long long
#define ld long double
#define M 1000000007
#define N (1<<22)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second

using namespace std;

vector<pii> v[N][2];
vector<int> ms;
bitset<N> e[2];

void dfs (int i, int x) {
	if (e[x][i]) return;
	e[x][i] = 1;
	for (pii p : v[i][x]) {
		dfs(p.F, p.S);
	}
}

int main () {
	cin.sync_with_stdio(false);
	cin.tie(0);

	int n;
	int m;
	cin>>n>>m;
	for (int i = 1; i <= m; i++) {
		int x;
		cin>>x;
		ms.push_back(x);
	}
	sort(ms.begin(), ms.end());
	for (int i : ms) {
		v[i][0].push_back({i, 1});
		v[(1<<n) - 1 - i][1].push_back({i, 0});
	}
	for (int i = 0; i < (1<<n); i++) {
		for (int j = 0; j < n; j++) {
			v[i][1].push_back({i | (1<<j), 1});
		}
	}
	int ans = 0;
	for (int i : ms) {
		if (!e[0][i]) {
			ans++;
			dfs(i, 0);
		}
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>

#define INF 1000000001
#define LINF 1000000000000000001LL
#define ll long long
#define ld long double
#define M 1000000007
#define N (1<<22)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second

using namespace std;

vector<int> ms;
bitset<N> e[2];
int n;
int im[N];

void dfs (int i, int x) {
	if (e[x][i]) return;
	e[x][i] = 1;
	if (!x && im[i]) {
		dfs(i, 1);
	} else if (x) {
		for (int j = 0; j < n; j++) {
			dfs(i | (1<<j), 1);
		}
		dfs((1<<n) - 1 - i, 0);
	}
}

int main () {
	cin.sync_with_stdio(false);
	cin.tie(0);

	int m;
	cin>>n>>m;
	for (int i = 1; i <= m; i++) {
		int x;
		cin>>x;
		ms.push_back(x);
		im[x] = 1;
	}
	sort(ms.begin(), ms.end());

	int ans = 0;

	for (int i : ms) {
		if (!e[0][i]) {
			ans++;
			dfs(i, 0);
		}
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define N 8500010
using namespace std;

vector<int> g[N];
int total,n,m;
bool v[N];

void dfs(int x)
{
    v[x]=1;
    for(int y:g[x])
    {
        if (v[y]) continue;
        dfs(y);
    }
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>m; total=(1<<n)-1;

	for(int i=0;i<=total;i++)
    {
        for(int j=0;j<n;j++)
            if ((i&(1<<j))==0) g[i].emplace_back(i|(1<<j));
        g[i].shrink_to_fit();
    }
    for(int i=1;i<=m;i++)
    {
        int x; cin>>x;
        g[total+i].emplace_back(x);
        g[total-x].emplace_back(total+i);
    }
    int ans=0;
    for(int i=1;i<=m;i++)
        if (!v[total+i]) {ans++; dfs(total+i);}
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define N 10000010
using namespace std;

int a[N],total,n,m;
bool v[N];

void dfs(int x)
{
    v[x]=1;
    for(int i=0;i<n;i++)
        if ((x&(1<<i))==0) dfs(x|(1<<i));
    if (!v[total+total^x]) dfs(total+total^x);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>m; total=(1<<n)-1;

    for(int i=1;i<=m;i++) cin>>a[i];
    int ans=0;
    for(int i=1;i<=m;i++)
        if (!v[total+a[i]])
        {
            v[total+a[i]]=1;
            ans++; dfs(a[i]);
        }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define N 1<<22
using namespace std;

int a[N],total,n,m;
bool v[N],p[N];

void dfs(int x)
{
    v[x]=1;
    for(int i=0;i<n;i++)
        if ((x&(1<<i))==0&&!v[x^(1<<i)]) dfs(x^(1<<i));
    if (p[total^x]&&!v[total^x]) dfs(total^x);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>m; total=(1<<n)-1;

    for(int i=1;i<=m;i++)
        {cin>>a[i];p[a[i]]=1;}
    int ans=0;
    for(int i=1;i<=m;i++)
        if (!v[total^a[i]]) {ans++; if (!v[a[i]])dfs(a[i]);}
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define N 1<<22
using namespace std;

int a[N],total,n,m;
bool v[N],p[N];

void dfs(int x)
{
    v[x]=1;
    for(int i=0;i<n;i++)
        if ((x&(1<<i))==0&&!v[x^(1<<i)]) dfs(x^(1<<i));
    if (p[total^x]&&!v[total^x]) dfs(total^x);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>m; total=(1<<n)-1;

    for(int i=1;i<=m;i++)
        {cin>>a[i];p[a[i]]=1;}
    int ans=0;
    for(int i=1;i<=m;i++)
        if (!v[a[i]]) {ans++; dfs(a[i]);}
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define N 9000010
using namespace std;

vector<int> g[N];
int total,n,m;
bool v[N];

void dfs(int x)
{
    v[x]=1;
    for(int y:g[x])
    {
        if (v[y]) continue;
        dfs(y);
    }
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>m; total=(1<<n)-1;

	for(int i=0;i<=total;i++)
    {
        for(int j=0;j<n;j++)
            if ((i&(1<<j))==0) g[i].emplace_back(i|(1<<j));
    }
    for(int i=1;i<=m;i++)
    {
        int x; cin>>x;
        g[total+i].emplace_back(x);
        g[total-x].emplace_back(total+i);
    }
    int ans=0;
    for(int i=1;i<=m;i++)
        if (!v[total+i]) {ans++; dfs(total+i);}
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long Long;

const int N = 22;

int arr[1 << N];
bool inArr[1 << N];
int n, m;

struct DSU {
  int parent[1 << N];
  int rank[1 << N];

  int getRoot(int node) {
    if (parent[node] == node) return node;
    return parent[node] = getRoot(parent[node]);
  }

  void join(int x, int y) {
    x = getRoot(x), y = getRoot(y);
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    parent[y] = x;
  }

  DSU() {
    for (int i = 0; i < (1 << N); ++i) {
      parent[i] = i;
    }
  }

} dsu;

bool vis[1 << N];
bool connected[1 << N];

void buildConnected(int node) {
  if (vis[node]) return;
  vis[node] = true;

  connected[node] = inArr[node];

  for (int i = 0; i < N; ++i) {
    if ((node >> i) & 1) {
      buildConnected(node ^ (1 << i));
      connected[node] |= connected[node ^ (1 << i)];
    }
  }
}

void dfs(int node, int lst = 0) {
  if (vis[node]) return;
  vis[node] = true;

  for (int i = lst; i < N; ++i) {
    if (((node >> i) & 1) && connected[node ^ (1 << i)]) {
      dsu.join(node, node ^ (1 << i));
      dfs(node ^ (1 << i), i + 1);
    }
  }

}

void build() {
  buildConnected((1 << N) - 1);
  memset(vis, 0, sizeof vis);

  for (int i = 0; i < m; ++i) {
    if (connected[((1 << N) - 1) ^ arr[i]]) {
      dfs(((1 << N) - 1) ^ arr[i]);
      dsu.join(arr[i], ((1 << N) - 1) ^ arr[i]);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    cin >> arr[i];
    inArr[arr[i]] = true;
  }

  build();

  int res = 0;

  memset(vis , false , sizeof vis);
  for (int i = 0; i < m; ++i) {
    vis[dsu.getRoot(arr[i])] = true;
  }

  cout << count(vis , vis + (1 << N) , true);

}


#include <bits/stdc++.h>
using namespace std;

typedef long long Long;

const int N = 22;

int arr[1 << N];
bool inArr[1 << N];
int n, m;

struct DSU {
  int parent[1 << N];

  int getRoot(int node) {
    if (parent[node] == node) return node;
    return parent[node] = getRoot(parent[node]);
  }

  void join(int x, int y) {
    x = getRoot(x), y = getRoot(y);
    if (inArr[x]) swap(x, y);
    parent[x] = y;
  }

  DSU() {
    for (int i = 0; i < (1 << N); ++i) {
      parent[i] = i;
    }
  }

} dsu;

bool vis[1 << N];
bool connected[1 << N];

bool dfs(int node, int lst = 1) {
  if (vis[node]) return connected[node];
  vis[node] = true;

  bool exists = inArr[node];

  for (int i = lst; i < N; ++i) {
    if ((node >> i) & 1) {
      dsu.join(node, node ^ (1 << i));
      exists |= dfs(node ^ (1 << i), i);
    }
  }

  return connected[node] = exists;
}

void build() {
  for (int i = 0; i < m; ++i) {
    if (dfs(((1 << N) - 1) ^ arr[i])) {
      dsu.join(arr[i], ((1 << N) - 1) ^ arr[i]);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    cin >> arr[i];
    inArr[arr[i]] = true;
  }

  build();

  int res = 0;

  for (int i = 0; i < m; ++i) {
    if (dsu.getRoot(arr[i]) == arr[i]) {
      ++res;
    }
  }

  cout << res;

}


#include <bits/stdc++.h>
using namespace std;

typedef long long Long;

const int N = 22;

int arr[1 << N];
bool inArr[1 << N];
int n, m;

struct DSU {
  int parent[1 << N];

  int getRoot(int node) {
    if (parent[node] == node) return node;
    return parent[node] = getRoot(parent[node]);
  }

  void join(int x, int y) {
    x = getRoot(x), y = getRoot(y);
    if (inArr[x]) swap(x, y);
    parent[x] = y;
  }

  DSU() {
    for (int i = 0; i < (1 << N); ++i) {
      parent[i] = i;
    }
  }

} dsu;

bool vis[1 << N];
bool connected[1 << N];

void buildConnected(int node) {
  if (vis[node]) return;
  vis[node] = true;

  connected[node] = inArr[node];

  for (int i = 0; i < N; ++i) {
    if ((node >> i) & 1) {
      buildConnected(node ^ (1 << i));
      connected[node] |= connected[node ^ (1 << i)];
    }
  }
}

void dfs(int node, int lst = 0) {
  if (vis[node]) return;
  vis[node] = true;

  for (int i = lst; i < N; ++i) {
    if (((node >> i) & 1) && connected[node ^ (1 << i)]) {
      dsu.join(node, node ^ (1 << i));
      dfs(node ^ (1 << i), i + 1);
    }
  }

}

void build() {
  buildConnected((1 << N) - 1);
  memset(vis, 0, sizeof vis);

  for (int i = 0; i < m; ++i) {
    if (connected[((1 << N) - 1) ^ arr[i]]) {
      dfs(((1 << N) - 1) ^ arr[i]);
      dsu.join(arr[i], ((1 << N) - 1) ^ arr[i]);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    cin >> arr[i];
    inArr[arr[i]] = true;
  }

  build();

  int res = 0;

  for (int i = 0; i < m; ++i) {
    if (dsu.getRoot(arr[i]) == arr[i]) {
      ++res;
    }
  }

  cout << res;

}


#include <bits/stdc++.h>
using namespace std;

typedef long long Long;

const int N = 22;

int arr[1 << N];
bool inArr[1 << N];
int n, m;

struct DSU {
  int parent[1 << N];

  int getRoot(int node) {
    if (parent[node] == node) return node;
    return parent[node] = getRoot(parent[node]);
  }

  void join(int x, int y) {
    x = getRoot(x), y = getRoot(y);
    if (inArr[x]) swap(x, y);
    parent[x] = y;
  }

  DSU() {
    for (int i = 0; i < (1 << N); ++i) {
      parent[i] = i;
    }
  }

} dsu;

bool vis[1 << N];
bool connected[1 << N];

bool dfs(int node, int lst = 0) {
  if (vis[node]) return connected[node];
  vis[node] = true;

  bool exists = inArr[node];

  for (int i = lst; i < N; ++i) {
    if ((node >> i) & 1) {
      dsu.join(node, node ^ (1 << i));
      exists |= dfs(node ^ (1 << i), i);
    }
  }

  return connected[node] = exists;
}

void build() {
  for (int i = 0; i < m; ++i) {
    if (dfs(((1 << N) - 1) ^ arr[i])) {
      dsu.join(arr[i], ((1 << N) - 1) ^ arr[i]);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    cin >> arr[i];
    inArr[arr[i]] = true;
  }

  build();

  int res = 0;

  for (int i = 0; i < m; ++i) {
    if (dsu.getRoot(arr[i]) == arr[i]) {
      ++res;
    }
  }

  cout << res;

}


#include <bits/stdc++.h>
using namespace std;

typedef long long Long;

const int N = 22;

int arr[1 << N];
bool inArr[1 << N];
int n, m;

struct DSU {
  int parent[1 << N];

  int getRoot(int node) {
    if (parent[node] == node) return node;
    return parent[node] = getRoot(parent[node]);
  }

  void join(int x, int y) {
    x = getRoot(x), y = getRoot(y);
    if (inArr[x]) swap(x, y);
    parent[x] = y;
  }

  DSU() {
    for (int i = 0; i < (1 << N); ++i) {
      parent[i] = i;
    }
  }

} dsu;

bool vis[1 << N];
bool connected[1 << N];

void buildConnected(int node) {
  if (vis[node]) return;
  vis[node] = true;

  connected[node] = inArr[node];

  for (int i = 0; i < N; ++i) {
    if ((node >> i) & 1) {
      buildConnected(node ^ (1 << i));
      connected[node] |= connected[node ^ (1 << i)];
    }
  }
}

void dfs(int node, int lst = 0) {
  if (vis[node]) return;
  vis[node] = true;

  for (int i = 0; i < N; ++i) {
    if ((node >> i) & 1) {
      dsu.join(node, node ^ (1 << i));
    }
  }

}

void build() {
  buildConnected((1 << N) - 1);
  memset(vis, 0, sizeof vis);

  for (int i = 0; i < m; ++i) {
    if (connected[((1 << N) - 1) ^ arr[i]]) {
      dfs(((1 << N) - 1) ^ arr[i]);
      dsu.join(arr[i], ((1 << N) - 1) ^ arr[i]);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    cin >> arr[i];
    inArr[arr[i]] = true;
  }

  build();

  int res = 0;

  for (int i = 0; i < m; ++i) {
    if (dsu.getRoot(arr[i]) == arr[i]) {
      ++res;
    }
  }

  cout << res;

}


#include <bits/stdc++.h>
using namespace std;

typedef long long Long;

const int N = 22;

int arr[1 << N];
bool inArr[1 << N];
int n, m;

struct DSU {
  int parent[1 << N];

  int getRoot(int node) {
    if (parent[node] == node) return node;
    return parent[node] = getRoot(parent[node]);
  }

  void join(int x, int y) {
    x = getRoot(x), y = getRoot(y);
    parent[y] = x;
  }

  DSU() {
    for (int i = 0; i < (1 << N); ++i) {
      parent[i] = i;
    }
  }

} dsu;

bool vis[1 << N];
bool connected[1 << N];

void buildConnected(int node) {
  if (vis[node]) return;
  vis[node] = true;

  connected[node] = inArr[node];

  for (int i = 0; i < N; ++i) {
    if ((node >> i) & 1) {
      buildConnected(node ^ (1 << i));
      connected[node] |= connected[node ^ (1 << i)];
    }
  }
}

void dfs(int node, int lst = 0) {
  if (vis[node]) return;
  vis[node] = true;

  for (int i = lst; i < N; ++i) {
    if (((node >> i) & 1) && connected[node ^ (1 << i)]) {
      dsu.join(node, node ^ (1 << i));
      dfs(node ^ (1 << i), i + 1);
    }
  }

}

void build() {
  buildConnected((1 << N) - 1);
  memset(vis, 0, sizeof vis);

  for (int i = 0; i < m; ++i) {
    if (connected[((1 << N) - 1) ^ arr[i]]) {
      dfs(((1 << N) - 1) ^ arr[i]);
      dsu.join(arr[i], ((1 << N) - 1) ^ arr[i]);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    cin >> arr[i];
    inArr[arr[i]] = true;
  }

  build();

  memset(vis , false , sizeof vis);
  for (int i = 0; i < m; ++i) {
    vis[dsu.getRoot(arr[i])] = true;
  }

  cout << count(vis , vis + (1 << N) , true);

}


#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REYNA(i, a, b) for (int i=(a); i<(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const ll INF = 1e18;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int maxn = (1 << 22);

int n, m;
bitset <maxn> odw, jest;
int tab[maxn];
int f[maxn];
inline int find(int a)
{
	if (f[a] == a) return a;
	f[a] = find(f[a]);
	return f[a];
}
int c;

void lacz(int a, int b)
{
	a = find(a); b = find(b);
	if (a == b) return;
	c--;
	if (a & 1) f[a] = b;
	else f[b] = a;
}

vector <int> best[maxn];
const int C = 3;
const int D = 20;

int main()
{
	boost;
	cin >> m >> n;
	c = n;
	FOR(i, 0, (1 << m)-1) f[i] = i;
	FOR(i, 1, n)
	{
		cin >> tab[i];
		jest[tab[i]] = 1;
		if (tab[i] == 0) OUT(1);
		best[tab[i]].pb(tab[i]);
	}

	sort(tab+1, tab+n+1);
	FOR(i, 1, min(D, n))
	{
		FOR(j, 1, n)
			if (i != j && ((tab[i] & tab[j]) == 0)) lacz(tab[i], tab[j]);
	}

	if (n <= 1000)
	{
		FOR(i, 1, n)
			FOR(j, i + 1, n)
				if ((tab[i] & tab[j]) == 0) lacz(tab[i], tab[j]);
	}
	int pot = (1 << m);
	FOR(i, 0, pot -1)
	{
		FOR(j, 0, m - 1)
			if (i & (1 << j))
			{
				for (auto u : best[i ^ (1 << j)]) best[i].pb(u);
				sort(best[i].begin(), best[i].end());
				best[i].resize(distance(best[i].begin(), unique(best[i].begin(), best[i].end())));
				best[i].resize(min((int)best[i].size(), C));
			}
	}

	FOR(i, 1, n)
	{
		int pp = 0;
		FOR(j, 0, m-1)
		{
			int bit = (tab[i] & (1 << j))?0:1;
			pp += bit * (1 << j);
		}
		if (!best[pp].empty())
		{
			for (auto u : best[pp])
			{
				lacz(u, tab[i]);
			}
		}
	}

	cout << c << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REYNA(i, a, b) for (int i=(a); i<(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const ll INF = 1e18;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int maxn = (1 << 22);

int dr[maxn + 5], n, m;
bitset <maxn> odw, jest;
int tab[maxn];
vector <int> v[maxn];

void dfs(int x)
{
	odw[x] = 1;
	for (auto u : v[x])
		if (!odw[u]) dfs(u);
}

int best[maxn];
int main()
{
	boost;
	cin >> m >> n;
	FOR(i, 0, 1<<m) best[i] = inf;
	FOR(i, 1, n)
	{
		cin >> tab[i];
		jest[tab[i]] = 1;
		if (tab[i] == 0) OUT(1);
		best[tab[i]] = tab[i];
	}
	int pot = (1 << m);
	FOR(i, 0, pot -1)
	{
		FOR(j, 0, m - 1)
			if (i & (1 << j)) best[i] = min(best[i], best[i ^ (1 << j)]);
	}

	FOR(i, 1, n)
	{
		int pp = 0;
		FOR(j, 0, m-1)
		{
			int bit = (tab[i] & (1 << j))?0:1;
			pp += bit * (1 << j);
		}
		if (best[pp] != inf)
		{
			v[best[pp]].pb(tab[i]);
			v[tab[i]].pb(best[pp]);
		}
	}

	int c = 0;
	FOR(i, 0, pot-1)
	{
		if (!jest[tab[i]]) continue;
		if (!odw[tab[i]])
		{
			++c;
			dfs(tab[i]);
		}
	}

	cout << c << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REYNA(i, a, b) for (int i=(a); i<(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const ll INF = 1e18;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int maxn = (1 << 22);

int n, m;
bitset <maxn> odw, jest;
int tab[maxn];
int f[maxn];
inline int find(int a)
{
	if (f[a] == a) return a;
	f[a] = find(f[a]);
	return f[a];
}
int c;

void lacz(int a, int b)
{
	a = find(a); b = find(b);
	if (a == b) return;
	c--;
	if (a & 1) f[a] = b;
	else f[b] = a;
}

vector <int> best[maxn];
const int C = 4;
const int D = 200;

int main()
{
	boost;
	cin >> m >> n;
	c = n;
	FOR(i, 0, (1 << m)-1) f[i] = i;
	FOR(i, 1, n)
	{
		cin >> tab[i];
		jest[tab[i]] = 1;
		if (tab[i] == 0) OUT(1);
		best[tab[i]].pb(tab[i]);
	}

	sort(tab+1, tab+n+1);
	FOR(i, 1, min(D, n))
	{
		FOR(j, 1, n)
			if (i != j && ((tab[i] & tab[j]) == 0)) lacz(tab[i], tab[j]);
	}

	if (n <= 1000)
	{
		FOR(i, 1, n)
			FOR(j, i + 1, n)
				if ((tab[i] & tab[j]) == 0) lacz(tab[i], tab[j]);
	}
	int pot = (1 << m);
	FOR(i, 0, pot -1)
	{
		FOR(j, 0, m - 1)
			if (i & (1 << j))
			{
				for (auto u : best[i ^ (1 << j)]) best[i].pb(u);
				sort(best[i].begin(), best[i].end());
				best[i].resize(distance(best[i].begin(), unique(best[i].begin(), best[i].end())));
				best[i].resize(min((int)best[i].size(), C));
			}
	}

	FOR(i, 1, n)
	{
		int pp = 0;
		FOR(j, 0, m-1)
		{
			int bit = (tab[i] & (1 << j))?0:1;
			pp += bit * (1 << j);
		}
		if (!best[pp].empty())
		{
			for (auto u : best[pp])
			{
				lacz(u, tab[i]);
			}
		}
	}

	cout << c << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REYNA(i, a, b) for (int i=(a); i<(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const ll INF = 1e18;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int maxn = (1 << 22);

int n, m;
bitset <maxn> odw, jest;
int tab[maxn];
int f[maxn];
inline int find(int a)
{
	if (f[a] == a) return a;
	f[a] = find(f[a]);
	return f[a];
}
int c;

void lacz(int a, int b)
{
	a = find(a); b = find(b);
	if (a == b) return;
	c--;
	if (a & 1) f[a] = b;
	else f[b] = a;
}

vector <int> best[maxn];
const int C = 2;
const int D = 50;

int main()
{
	boost;
	cin >> m >> n;
	c = n;
	FOR(i, 0, (1 << m)-1) f[i] = i;
	FOR(i, 1, n)
	{
		cin >> tab[i];
		jest[tab[i]] = 1;
		if (tab[i] == 0) OUT(1);
		best[tab[i]].pb(tab[i]);
	}

	sort(tab+1, tab+n+1);
	FOR(i, 1, min(D, n))
	{
		FOR(j, 1, n)
			if (i != j && ((tab[i] & tab[j]) == 0)) lacz(tab[i], tab[j]);
	}

	if (n <= 1000)
	{
		FOR(i, 1, n)
			FOR(j, i + 1, n)
				if ((tab[i] & tab[j]) == 0) lacz(tab[i], tab[j]);
	}
	int pot = (1 << m);
	FOR(i, 0, pot -1)
	{
		FOR(j, 0, m - 1)
			if (i & (1 << j))
			{
				for (auto u : best[i ^ (1 << j)]) best[i].pb(u);
				sort(best[i].begin(), best[i].end());
				best[i].resize(distance(best[i].begin(), unique(best[i].begin(), best[i].end())));
				best[i].resize(min((int)best[i].size(), C));
			}
	}

	FOR(i, 1, n)
	{
		int pp = 0;
		FOR(j, 0, m-1)
		{
			int bit = (tab[i] & (1 << j))?0:1;
			pp += bit * (1 << j);
		}
		if (!best[pp].empty())
		{
			for (auto u : best[pp])
			{
				lacz(u, tab[i]);
			}
		}
	}

	cout << c << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REYNA(i, a, b) for (int i=(a); i<(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const ll INF = 1e18;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int maxn = (1 << 22);

int n, m;
bitset <maxn> odw, jest;
int tab[maxn];
vector <int> v[maxn];
void dfs(int x)
{
	odw[x] = 1;
	for (auto u : v[x])
		if (!odw[u]) dfs(u);
}

vector <int> best[maxn];
const int C = 4;
int main()
{
	boost;
	cin >> m >> n;
	FOR(i, 1, n)
	{
		cin >> tab[i];
		jest[tab[i]] = 1;
		if (tab[i] == 0) OUT(1);
		best[tab[i]].pb(tab[i]);
	}

	if (n <= 1000)
	{
		FOR(i, 1, n)
			FOR(j, i + 1, n)
				if ((tab[i] & tab[j]) == 0) v[tab[i]].pb(tab[j]), v[tab[j]].pb(tab[i]);
	}
	int pot = (1 << m);
	FOR(i, 0, pot -1)
	{
		FOR(j, 0, m - 1)
			if (i & (1 << j))
			{
				for (auto u : best[i ^ (1 << j)]) best[i].pb(u);
				sort(best[i].begin(), best[i].end());
				best[i].resize(distance(best[i].begin(), unique(best[i].begin(), best[i].end())));
				best[i].resize(min((int)best[i].size(), C));
			}
	}

	FOR(i, 1, n)
	{
		int pp = 0;
		FOR(j, 0, m-1)
		{
			int bit = (tab[i] & (1 << j))?0:1;
			pp += bit * (1 << j);
		}
		if (!best[pp].empty())
		{
			for (auto u : best[pp])
			{
				v[u].pb(tab[i]);
				v[tab[i]].pb(u);
			}
		}
	}

	int c = 0;
	FOR(i, 0, pot-1)
	{
		if (!jest[tab[i]]) continue;
		if (!odw[tab[i]])
		{
			++c;
			dfs(tab[i]);
		}
	}

	cout << c << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REYNA(i, a, b) for (int i=(a); i<(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const ll INF = 1e18;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int maxn = (1 << 22);

int n, m;
bitset <maxn> odw, jest;
int tab[maxn];
int f[maxn];
inline int find(int a)
{
	if (f[a] == a) return a;
	f[a] = find(f[a]);
	return f[a];
}
int c;

void lacz(int a, int b)
{
	a = find(a); b = find(b);
	if (a == b) return;
	c--;
	if (a & 1) f[a] = b;
	else f[b] = a;
}

vector <int> best[maxn];
const int C = 3;
const int D = 200;

int main()
{
	boost;
	cin >> m >> n;
	c = n;
	FOR(i, 0, (1 << m)-1) f[i] = i;
	FOR(i, 1, n)
	{
		cin >> tab[i];
		jest[tab[i]] = 1;
		if (tab[i] == 0) OUT(1);
		best[tab[i]].pb(tab[i]);
	}

	sort(tab+1, tab+n+1);
	FOR(i, 1, min(D, n))
	{
		FOR(j, 1, n)
			if (i != j && ((tab[i] & tab[j]) == 0)) lacz(tab[i], tab[j]);
	}

	if (n <= 1000)
	{
		FOR(i, 1, n)
			FOR(j, i + 1, n)
				if ((tab[i] & tab[j]) == 0) lacz(tab[i], tab[j]);
	}
	int pot = (1 << m);
	FOR(i, 0, pot -1)
	{
		FOR(j, 0, m - 1)
			if (i & (1 << j))
			{
				for (auto u : best[i ^ (1 << j)]) best[i].pb(u);
				sort(best[i].begin(), best[i].end());
				best[i].resize(distance(best[i].begin(), unique(best[i].begin(), best[i].end())));
				best[i].resize(min((int)best[i].size(), C));
			}
	}

	FOR(i, 1, n)
	{
		int pp = 0;
		FOR(j, 0, m-1)
		{
			int bit = (tab[i] & (1 << j))?0:1;
			pp += bit * (1 << j);
		}
		if (!best[pp].empty())
		{
			for (auto u : best[pp])
			{
				lacz(u, tab[i]);
			}
		}
	}

	cout << c << endl;
}