//IN THE NAME OF GOD\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int maxn = 1e3+10 , maxk=3e4+10 , MOD = 1e9+7 , inf=1e9+10;

int mark[maxk] , f[maxk] , ans[maxn] , t1[maxn] , t2[maxn];
bool mk[maxn] , p[maxk];
vector <int> g[maxk];

bool dfs(int u , int t){
    if(mark[u])
        return false;
    mark[u]=1;
    for(int v:g[u])
        if(!f[v] || dfs(f[v] , 1-t))
        {
            if(!t)
                ans[u]=v;
            else
                ans[v]=u;
            f[v]=u;
            f[u]=v;
            return true;
        }
    return false;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    string s1,s2;
    cin>>n;
    for(int i=1 ; i<=n ; i++){
        cin>>s1>>s2;
        t1[i] = 26*26*(s1[0]-'A') + 26*(s1[1]-'A') + (s1[2]-'A');
        t1[i]+=1001;
        t2[i] = 26*26*(s1[0]-'A') + 26*(s1[1]-'A') + (s2[0]-'A');
        t2[i]+=1001;
        if(mark[t1[i]]==1){
            mk[f[t1[i]]]=true;
            ans[f[t1[i]]]=t2[f[t1[i]]];
            if(p[t2[f[t1[i]]]]){
                cout<<"NO";
                return 0;
            }
            p[t2[f[t1[i]]]]=true;
        }
        if(mark[t1[i]]>0){
            mk[i]=true;
            ans[i]=t2[i];
            if(p[t2[i]]){
                cout<<"NO";
                return 0;
            }
            p[t2[i]]=true;
        }
        mark[t1[i]]++;
        f[t1[i]]=i;
    }
    memset(mark , 0 , sizeof(mark));
    memset(f , 0 , sizeof(f));
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        if(!p[t1[i]]){
            g[i].push_back(t1[i]);
            g[t1[i]].push_back(i);
        }
        if(!p[t2[i]]){
            g[i].push_back(t2[i]);
            g[t2[i]].push_back(i);
        }
    }
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        if(!f[i])
            dfs(i , 0);
    }
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        if(!f[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(int i=1 ; i<=n ; i++){
        char a,b,c;
        ans[i]-=1001;
        a=char('A'+(ans[i]%26));
        ans[i]-=(ans[i]%26);
        ans[i]/=26;
        b=char('A'+(ans[i]%26));
        ans[i]-=(ans[i]%26);
        ans[i]/=26;
        c=char('A'+(ans[i]%26));
        cout<<c<<b<<a<<endl;
    }
    return 0;
}


//IN THE NAME OF GOD\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int maxn = 1e3+10 , maxk=1e5+10 , MOD = 1e9+7 , inf=1e9+10;

int mark[maxk] , f[maxk] , ans[maxn] , t1[maxn] , t2[maxn];
bool mk[maxn] , p[maxk];
vector <int> g[maxk];

bool dfs(int u , int t){
    if(mark[u])
        return false;
    mark[u]=1;
    for(int v:g[u])
        if(!f[v] || dfs(f[v] , 1-t))
        {
            if(!t)
                ans[u]=v;
            else
                ans[v]=u;
            f[v]=u;
            f[u]=v;
            return true;
        }
    return false;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    string s1,s2;
    cin>>n;
    for(int i=1 ; i<=n ; i++){
        cin>>s1>>s2;
        t1[i] = 27*27*(s1[0]-'A') + 27*(s1[1]-'A') + (s1[2]-'A');
        t1[i]+=10000;
        t2[i] = 27*27*(s1[0]-'A') + 27*(s1[1]-'A') + (s2[0]-'A');
        t2[i]+=10000;
        if(mark[t1[i]]==1){
            mk[f[t1[i]]]=true;
            ans[f[t1[i]]]=t2[f[t1[i]]];
            if(p[t2[f[t1[i]]]]){
                cout<<"NO";
                return 0;
            }
            p[t2[f[t1[i]]]]=true;
        }
        if(mark[t1[i]]>0){
            mk[i]=true;
            ans[i]=t2[i];
            if(p[t2[i]]){
                cout<<"NO";
                return 0;
            }
            p[t2[i]]=true;
        }
        mark[t1[i]]++;
        f[t1[i]]=i;
    }
    memset(mark , 0 , sizeof(mark));
    memset(f , 0 , sizeof(f));
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        if(!p[t1[i]]){
            g[i].push_back(t1[i]);
            g[t1[i]].push_back(i);
        }
        if(!p[t2[i]]){
            g[i].push_back(t2[i]);
            g[t2[i]].push_back(i);
        }
    }
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        memset(mark , 0 , sizeof(mark));
        if(!f[i])
            dfs(i , 0);
    }
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        if(!f[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(int i=1 ; i<=n ; i++){
        char a,b,c;
        ans[i]-=10000;
        a=char('A'+(ans[i]%27));
        ans[i]-=(ans[i]%27);
        ans[i]/=27;
        b=char('A'+(ans[i]%27));
        ans[i]-=(ans[i]%27);
        ans[i]/=27;
        c=char('A'+(ans[i]%27));
        cout<<c<<b<<a<<endl;
    }
    return 0;
}


//IN THE NAME OF GOD\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int maxn = 1e3+10 , maxk=3e4+10 , MOD = 1e9+7 , inf=1e9+10;

int mark[maxk] , f[maxk] , ans[maxn] , t1[maxn] , t2[maxn];
bool mk[maxn] , p[maxk];
vector <int> g[maxk];

bool dfs(int u , int t){
    if(mark[u])
        return false;
    mark[u]=1;
    for(int v:g[u])
        if(!f[v] || dfs(f[v] , 1-t))
        {
            if(!t)
                ans[u]=v;
            else
                ans[v]=u;
            f[v]=u;
            f[u]=v;
            return true;
        }
    return false;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    string s1,s2;
    cin>>n;
    for(int i=1 ; i<=n ; i++){
        cin>>s1>>s2;
        t1[i] = 26*26*(s1[0]-'A') + 26*(s1[1]-'A') + (s1[2]-'A');
        t1[i]+=1001;
        t2[i] = 26*26*(s1[0]-'A') + 26*(s1[1]-'A') + (s2[0]-'A');
        t2[i]+=1001;
        if(mark[t1[i]]==1){
            mk[f[t1[i]]]=true;
            ans[f[t1[i]]]=t2[f[t1[i]]];
            if(p[t2[f[t1[i]]]]){
                cout<<"NO";
                return 0;
            }
            p[t2[f[t1[i]]]]=true;
        }
        if(mark[t1[i]]>0){
            mk[i]=true;
            ans[i]=t2[i];
            if(p[t2[i]]){
                cout<<"NO";
                return 0;
            }
            p[t2[i]]=true;
        }
        mark[t1[i]]++;
        f[t1[i]]=i;
    }
    memset(mark , 0 , sizeof(mark));
    memset(f , 0 , sizeof(f));
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        if(!p[t1[i]]){
            g[i].push_back(t1[i]);
            g[t1[i]].push_back(i);
        }
        if(!p[t2[i]]){
            g[i].push_back(t2[i]);
            g[t2[i]].push_back(i);
        }
    }
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        memset(mark , 0 , sizeof(mark));
        if(!f[i])
            dfs(i , 0);
    }
    for(int i=1 ; i<=n ; i++){
        if(mk[i])
            continue;
        if(!f[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(int i=1 ; i<=n ; i++){
        char a,b,c;
        ans[i]-=1001;
        a=char('A'+(ans[i]%26));
        ans[i]-=(ans[i]%26);
        ans[i]/=26;
        b=char('A'+(ans[i]%26));
        ans[i]-=(ans[i]%26);
        ans[i]/=26;
        c=char('A'+(ans[i]%26));
        cout<<c<<b<<a<<endl;
    }
    return 0;
}


//IN THE NAME OF GOD\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int maxn = 1e3+10 , maxk=1e5+10 , MOD = 1e9+7 , inf=1e9+10;

vector < pair <string , string> > v;
string s1[maxn] , s2[maxn];
int mark[maxk] , f[maxk] , ans[maxn] , t1[maxn] , t2[maxn];
bool mk[maxk] , p[maxk];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=0 ; i<n ; i++){
        cin>>s1[i]>>s2[i];
        t1[i] = 27*27*(s1[i][0]-'A') + 27*(s1[i][1]-'A') + (s1[i][2]-'A');
        t2[i] = 27*27*(s1[i][0]-'A') + 27*(s1[i][1]-'A') + (s2[i][0]-'A');
        if(mark[t1[i]]==1){
            mk[f[t1[i]]]=true;
            ans[f[t1[i]]]=t2[f[t1[i]]];
            if(p[t2[f[t1[i]]]]){
                cout<<"NO";
                return 0;
            }
            p[t2[f[t1[i]]]]=true;
        }
        if(mark[t1[i]]>0){
            mk[i]=true;
            ans[i]=t2[i];
            if(p[t2[i]]){
                cout<<"NO";
                return 0;
            }
            p[t2[i]]=true;
        }
        mark[t1[i]]++;
        f[t1[i]]=i;
    }
    for(int i=0 ; i<n ; i++){
        if(mk[i])
            continue;
        if(!p[t1[i]]){
            p[t1[i]]=true;
            ans[i]=t1[i];
        }
        else{
            if(p[t2[i]]){
                cout<<"NO";
                return 0;
            }
            p[t2[i]]=true;
            ans[i]=t2[i];
        }
    }
    cout<<"YES"<<endl;
    for(int i=0 ; i<n ; i++){
        char a,b,c;
        a=char('A'+(ans[i]%27));
        ans[i]-=(ans[i]%27);
        ans[i]/=27;
        b=char('A'+(ans[i]%27));
        ans[i]-=(ans[i]%27);
        ans[i]/=27;
        c=char('A'+(ans[i]%27));
        cout<<c<<b<<a<<endl;
    }
    return 0;
}


//IN THE NAME OF GOD\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int maxn = 1e3+10 , maxk=1e5+10 , MOD = 1e9+7 , inf=1e9+10;

vector < pair <string , string> > v;
string s1[maxn] , s2[maxn];
int mark[maxk] , f[maxk] , ans[maxn] , t1[maxn] , t2[maxn];
bool mk[maxk] , p[maxk];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=0 ; i<n ; i++){
        cin>>s1[i]>>s2[i];
        t1[i] = 27*27*(s1[i][0]-'A') + 27*(s1[i][1]-'A') + (s1[i][2]-'A');
        t2[i] = 27*27*(s1[i][0]-'A') + 27*(s1[i][1]-'A') + (s2[i][0]-'A');
        if(mark[t1[i]]==1){
            mk[f[t1[i]]]=true;
            ans[f[t1[i]]]=t2[f[t1[i]]];
            if(p[t2[f[t1[i]]]] || t2[f[t1[i]]]==t1[f[t1[i]]]){
                cout<<"NO";
                return 0;
            }
            p[t2[f[t1[i]]]]=true;
        }
        if(mark[t1[i]]>0){
            mk[i]=true;
            ans[i]=t2[i];
            if(p[t2[i]] || t1[i]==t2[i]){
                cout<<"NO";
                return 0;
            }
            p[t2[i]]=true;
        }
        mark[t1[i]]++;
        f[t1[i]]=i;
    }
    for(int i=0 ; i<n ; i++){
        if(mk[i])
            continue;
        if(!p[t1[i]]){
            p[t1[i]]=true;
            ans[i]=t1[i];
        }
        else{
            if(p[t2[i]]){
                cout<<"NO";
                return 0;
            }
            p[t2[i]]=true;
            ans[i]=t2[i];
        }
    }
    cout<<"YES"<<endl;
    for(int i=0 ; i<n ; i++){
        char a,b,c;
        a=char('A'+(ans[i]%27));
        ans[i]-=(ans[i]%27);
        ans[i]/=27;
        b=char('A'+(ans[i]%27));
        ans[i]-=(ans[i]%27);
        ans[i]/=27;
        c=char('A'+(ans[i]%27));
        cout<<c<<b<<a<<endl;
    }
    return 0;
}


//IN THE NAME OF GOD\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int maxn = 1e3+10 , MOD = 1e9+7 , inf=1e9+10;

string s[maxn] , t[maxn] , ans[maxn];
bool mark[maxn] , sw;
map <string , bool> mp;
map <string , int> m;
vector <int> v;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=1 ; i<=n ; i++){
        cin>>s[i]>>t[i];
        s[i] = s[i].substr(0 , 3);
        t[i] = s[i].substr(0 , 2) + t[i][0];
    }
    for(int i=1 ; i<=n ; i++){
        sw=false;
        if(!mark[i]){
            for(int j=i+1 ; j<=n ; j++){
                if(s[i] == s[j]){
                    if(!sw){
                        mark[i]=true;
                        sw=true;
                        ans[i]=t[i];
                        if(mp[t[i]]){
                            cout<<"NO";
                            return 0;
                        }
                        mp[t[i]]=true;
                        v.push_back(i);
                    }
                    v.push_back(j);
                    mark[j]=true;
                    ans[j]=t[j];
                    if(mp[t[j]]){
                        cout<<"NO";
                        return 0;
                    }
                    mp[t[j]]=true;
                }
            }
        }
        if(!mark[i])
            m[s[i]]=i;
    }
    for(int i:v){
        if(m[ans[i]]){
            int u = m[ans[i]];
            ans[u]=t[u];
            if(mp[t[u]]){
                cout<<"NO";
                return 0;
            }
            mp[t[u]]=true;
            v.push_back(u);
        }
    }
    cout<<"YES"<<endl;
    for(int i=1 ; i<=n ; i++)
        if(ans[i] != "")
            cout<<ans[i]<<endl;
        else
            cout<<s[i]<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007
#define N 1005
#define XX (names[num][0].substr(0,3))
#define xx (names[num][0].substr(0,2) + names[num][1].substr(0,1))
using namespace std;
string names[1005][2],s[1005];
typedef vector<int> vec;
map<string,vec> f;
map<string,int> Gf;
int n,cnt,Fh[1005],F[2005];
bool vis[1005],G[1005][2005];
void GG()
{
	cout<<"NO"<<endl;
	exit(0);
}
bool Find(int u)
{
	if(vis[u]) return false;
	vis[u] = true;
	for(int i = 1;i <= cnt;i++)
	 if(G[u][i])
	  if(!F[i] || Find(F[i]))
	  {
	  	 F[i] = u;
	  	 Fh[u] = i;
	  	 return true;
	  }
	return false;
}
int main()
{
	cin.sync_with_stdio(false);
	cin>>n;
	for(int i = 1;i <= n;i++)
	{
		cin>>names[i][0]>>names[i][1];
		int num = i;
		f[XX].push_back(i);
		if(!Gf[xx])
		{
			Gf[xx] = ++cnt;
			s[cnt] = xx;
		}
		if(!Gf[XX])
		{
			Gf[XX] = ++cnt;
			s[cnt] = XX;
		}
		G[num][Gf[xx]] = G[num][Gf[XX]] = 1;
	}
	for(auto it : f)
	{
		if(it.second.size() != 1)
		{
			for(auto it2 : it.second)
			{
				int num = it2;
				G[num][Gf[XX]] = 0;
			}
		}
	}
	for(int i = 1;i <= n;i++)
	{
		memset(vis,0,sizeof(vis));
		if(!Find(i)) GG();
	}
	cout<<"YES"<<endl;
	for(int i = 1;i <= n;i++) cout<<s[Fh[i]]<<endl;
}


#include <bits/stdc++.h>
#define MOD 1000000007
#define N 1005
#define XX (names[num][0].substr(0,3))
#define xx (names[num][0].substr(0,2) + names[num][1].substr(0,1))
using namespace std;
string names[1005][2],s[1005];
typedef vector<int> vec;
map<string,vec> f;
map<string,int> Gf;
int n,cnt,Fh[1005],F[2005];
bool vis[1005],G[1005][2005];
void GG()
{
	cout<<"NO"<<endl;
	exit(0);
}
bool Find(int u)
{
	if(vis[u]) return false;
	vis[u] = true;
	for(int i = 1;i <= cnt;i++)
	 if(G[u][i])
	  if(!F[i] || Find(F[i]))
	  {
	  	 F[i] = u;
	  	 Fh[u] = i;
	  	 return true;
	  }
	return false;
}
int main()
{
	cin.sync_with_stdio(false);
	cin>>n;
	for(int i = 1;i <= n;i++)
	{
		cin>>names[i][0]>>names[i][1];
		int num = i;
		f[XX].push_back(i);
		if(!Gf[xx]) Gf[xx] = ++cnt;
		s[cnt] = xx;
		if(!Gf[XX]) Gf[XX] = ++cnt;
		s[cnt] = XX;
		G[num][Gf[xx]] = G[num][Gf[XX]] = 1;
	}
	for(auto it : f)
	{
		if(it.second.size() != 1)
		{
			for(auto it2 : it.second)
			{
				int num = it2;
				G[num][Gf[XX]] = 0;
			}
		}
	}
	for(int i = 1;i <= n;i++)
	{
		memset(vis,0,sizeof(vis));
		if(!Find(i)) GG();
	}
	cout<<"YES"<<endl;
	for(int i = 1;i <= n;i++) cout<<s[Fh[i]]<<endl;
}


#include <bits/stdc++.h>
#define MOD 1000000007
#define N 1005
#define XX (names[num][0].substr(0,3))
#define xx (names[num][0].substr(0,2) + names[num][1].substr(0,1))
using namespace std;
string names[2005][2],s[2005];
typedef vector<int> vec;
map<string,vec> f;
map<string,int> Gf;
int n,cnt,Fh[2005],F[2005];
bool vis[2005],G[2005][2005];
void GG()
{
	cout<<"NO"<<endl;
	exit(0);
}
bool Find(int u)
{
	if(vis[u]) return false;
	vis[u] = true;
	for(int i = 1;i <= cnt;i++)
	 if(G[u][i])
	  if(!F[i] || Find(F[i]))
	  {
	  	 F[i] = u;
	  	 Fh[u] = i;
	  	 return true;
	  }
	return false;
}
int main()
{
	cin.sync_with_stdio(false);
	cin>>n;
	for(int i = 1;i <= n;i++)
	{
		cin>>names[i][0]>>names[i][1];
		int num = i;
		f[XX].push_back(i);
		if(!Gf[xx])
		{
			Gf[xx] = ++cnt;
			s[cnt] = xx;
		}
		if(!Gf[XX])
		{
			Gf[XX] = ++cnt;
			s[cnt] = XX;
		}
		G[num][Gf[xx]] = G[num][Gf[XX]] = 1;
	}
	for(auto it : f)
	{
		if(it.second.size() != 1)
		{
			for(auto it2 : it.second)
			{
				int num = it2;
				G[num][Gf[XX]] = 0;
			}
		}
	}
	for(int i = 1;i <= n;i++)
	{
		memset(vis,0,sizeof(vis));
		if(!Find(i)) GG();
	}
	cout<<"YES"<<endl;
	for(int i = 1;i <= n;i++) cout<<s[Fh[i]]<<endl;
}


#include <bits/stdc++.h>
#define MOD 1000000007
#define N 1005
#define XX (names[num][0].substr(0,3))
#define xx (names[num][0].substr(0,2) + names[num][1].substr(0,1))
using namespace std;
string names[2005][2],s[2005];
typedef vector<int> vec;
map<string,vec> f;
map<string,int> Gf;
int n,cnt,Fh[2005],F[2005],G[2005][2005];
bool vis[2005];
void GG()
{
	cout<<"NO"<<endl;
	exit(0);
}
bool Find(int u)
{
	if(vis[u]) return false;
	vis[u] = true;
	for(int i = 1;i <= cnt;i++)
	 if(G[u][i])
	  if(!F[i] || Find(F[i]))
	  {
	  	 F[i] = u;
	  	 Fh[u] = i;
	  	 return true;
	  }
	return false;
}
int main()
{
	cin.sync_with_stdio(false);
	cin>>n;
	for(int i = 1;i <= n;i++)
	{
		cin>>names[i][0]>>names[i][1];
		int num = i;
		f[XX].push_back(i);
		if(!Gf[xx])
		{
			Gf[xx] = ++cnt;
			s[cnt] = xx;
		}
		if(!Gf[XX])
		{
			Gf[XX] = ++cnt;
			s[cnt] = XX;
		}
		G[num][Gf[xx]]++;
		G[num][Gf[XX]]++;
	}
	for(auto it : f)
	{
		if(it.second.size() != 1)
		{
			for(auto it2 : it.second)
			{
				int num = it2;
				G[num][Gf[XX]]--;
			}
		}
	}
	for(int i = 1;i <= n;i++)
	{
		memset(vis,0,sizeof(vis));
		if(!Find(i)) GG();
	}
	cout<<"YES"<<endl;
	for(int i = 1;i <= n;i++) cout<<s[Fh[i]]<<endl;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
int visited[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if(visited[idx]==3){
//			printf("entrei %s\n", s2.c_str());
			flag=false;
			break;
		}

		string aux;
		if(visited[idx])
			aux=s2;
		else if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		visited[idx]++;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[v[j].first]=0;
			used[aux]=idx;

			ans[idx]=aux;
		}else{
			used[aux]=idx;
			ans[idx]=aux;
//			printf("ans[%d]=%s\n", idx, aux.c_str());
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if((used[s1] || not canUseFirst[idx]) && used[s2]){
			flag=false;
			break;
		}

		if(used[s1]==idx) used[s1]=false;

		string aux;
		if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		if(used[aux]){
			q.push(used[aux]);
			used[aux]=idx;
		}else{
			used[aux]=true;
			ans[idx]=aux;
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if((used[s1] || not canUseFirst[idx]) && used[s2]){
			flag=false;
			break;
		}

		string aux;
		if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[v[j].first]=0;
			used[aux]=idx;
		}else{
			used[aux]=true;
			ans[idx]=aux;
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
int visited[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if(visited[idx]==2){
//			printf("entrei %s\n", s2.c_str());
			flag=false;
			break;
		}

		string aux;
		if(visited[idx])
			aux=s2;
		else if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		visited[idx]++;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[v[j].first]=0;
			used[aux]=idx;

			ans[idx]=aux;
		}else{
			used[aux]=idx;
			ans[idx]=aux;
//			printf("ans[%d]=%s\n", idx, aux.c_str());
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
int visited[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if(visited[idx] && used[s2]){
		//	printf("entrei %s\n", s2.c_str());
			flag=false;
			break;
		}

		visited[idx]++;

		string aux;
		if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[v[j].first]=0;
			used[aux]=idx;

			ans[idx]=aux;
		}else{
			used[aux]=idx;
			ans[idx]=aux;
//			printf("ans[%d]=%s\n", idx, aux.c_str());
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
int visited[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if(visited[idx]==2){
//			printf("entrei %s\n", s2.c_str());
			flag=false;
			break;
		}

		visited[idx]++;

		string aux;
		if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[v[j].first]=0;
			used[aux]=idx;
			ans[idx]=aux;
		}else{
			used[aux]=idx;
			ans[idx]=aux;
//			printf("ans[%d]=%s\n", idx, aux.c_str());
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if((used[s1] || not canUseFirst[idx]) && used[s2]){
			flag=false;
			break;
		}

		string aux;
		if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		if(used[aux]){
			q.push(used[aux]);
			used[aux]=idx;
		}else{
			used[aux]=true;
			ans[idx]=aux;
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
int visited[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if(visited[idx]==2){
			flag=false;
			break;
		}

		string aux;
		if(visited[idx])
			aux=s2;
		else if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		visited[idx]++;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[aux]=idx;

			ans[idx]=aux;
		}else{
			used[aux]=idx;
			ans[idx]=aux;
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
int visited[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if(visited[idx]==3){
		//	printf("entrei %s\n", s2.c_str());
			flag=false;
			break;
		}

		visited[idx]++;

		string aux;
		if(visited[idx])
			aux=s2;
		else if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[v[j].first]=0;
			used[aux]=idx;

			ans[idx]=aux;
		}else{
			used[aux]=idx;
			ans[idx]=aux;
//			printf("ans[%d]=%s\n", idx, aux.c_str());
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
bool canUseFirst[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	memset(canUseFirst, true, sizeof canUseFirst);

	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++){
			if(v[i].first==v[j].first){
				canUseFirst[i]=canUseFirst[j]=false;
			}
		}
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if((used[s1] || not canUseFirst[idx]) && used[s2]){
			flag=false;
			break;
		}

		string aux;
		if(canUseFirst[idx] && not used[s1])
			aux=s1;
		else
			aux=s2;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[v[j].first]=0;
			used[aux]=idx;
		}else{
			used[aux]=idx;
			ans[idx]=aux;
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>

#define MAX 2000

using namespace std;

typedef pair <string, string> ss;
typedef pair <int, int> ii;

queue <int> q;
int visited[MAX];
map <string, int> used;

int main(){
	int n;

	cin >> n;

	vector <string> ans(n+3);
	vector <ss> v(n+3);

	for(int i=1; i<=n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		v[i]=make_pair(s1.substr(0, 3), s1.substr(0, 2)+s2[0]);
		q.emplace(i);
	}

	bool flag=true;
	while(not q.empty()){
		int idx=q.front(); q.pop();
		string s1=v[idx].first, s2=v[idx].second;

		if(visited[idx]==2){
			flag=false;
			break;
		}

		string aux;
		if(visited[idx])
			aux=s2;
		else if(not used[s1])
			aux=s1;
		else
			aux=s2;

		visited[idx]++;

		if(used[aux]){
			int j=used[aux];
			q.push(j);
			used[aux]=idx;

			ans[idx]=aux;
		}else{
			used[aux]=idx;
			ans[idx]=aux;
		}
	}

	if(flag){
		cout << "YES" << endl;

		for(int i=1; i<=n; i++)
			cout << ans[i] << endl;
	}else
		cout << "NO" << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
const int maxn=1005;
const int maxl=25;
struct name
{
    string firstchose;
    string secondchose;
}fc[maxn];
string output[maxn];
int main()
{
    int n,i;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        string a, b;
        cin >> a >> b;
        fc[i].firstchose=a.substr(0, 3);
        fc[i].secondchose=a.substr(0, 2)+b.substr(0 ,1);
//        cout << fc[i].firstchose << endl;
//        cout << fc[i].secondchose << endl;
    }

    set <string> hadc;
    for(i=0;i<n;i++)
    {
        string x1=fc[i].firstchose;
        string x2=fc[i].secondchose;
        if(hadc.count(x2)&&hadc.count(x1)){
            printf("NO\n");return 0;
        }
        if(!hadc.count(x2)){//当二没有选
            hadc.insert(x2);
            output[i]=x2;
        }
    }
    cout << "YES\n";
    for(i=0;i<n;i++)
        cout << output[i] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
const int maxn=1005;
const int maxl=25;
struct name
{
    string firstchose;
    string secondchose;
}fc[maxn];
string output[maxn];
int main()
{
    int n,i;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        string a, b;
        cin >> a >> b;
        fc[i].firstchose=a.substr(0, 3);
        fc[i].secondchose=a.substr(0, 2)+b.substr(0 ,1);
//        cout << fc[i].firstchose << endl;
//        cout << fc[i].secondchose << endl;
    }

    set <string> hadc;
    set <string> hadcs;
    for(i=0;i<n;i++)
    {
        string x1=fc[i].firstchose;
        string x2=fc[i].secondchose;
        if(hadc.count(x2)){
            if(!hadcs.count(x2)){
                hadcs.insert(x2);
                output[i]=x2;
            }
            else if(!hadc.count(x1))
            {
                hadcs.insert(x1);
                hadc.insert(x1);
                output[i]=x1;
            }
            else{
                printf("NO\n");
                return 0;
            }
        }
        if(!hadc.count(x2)){//当二没有选
            hadcs.insert(x2);//单独选x2

            hadc.insert(x1);
            hadc.insert(x2);
            output[i]=x2;
        }
    }
    cout << "YES\n";
    for(i=0;i<n;i++)
        cout << output[i] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
const int maxn=1005;
const int maxl=25;
struct name
{
    string firstchose;
    string secondchose;
}fc[maxn];
string output[maxn];
int main()
{
    int n,i;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        string a, b;
        cin >> a >> b;
        fc[i].firstchose=a.substr(0, 3);
        fc[i].secondchose=a.substr(0, 2)+b.substr(0 ,1);
//        cout << fc[i].firstchose << endl;
//        cout << fc[i].secondchose << endl;
    }

    set <string> hadc;
    set <string> hadcs;
    for(i=0;i<n;i++)
    {
        string x1=fc[i].firstchose;
        string x2=fc[i].secondchose;
        if(hadc.count(x2)){
            if(!hadcs.count(x2)){
                hadcs.insert(x2);
                output[i]=x2;
            }
            else
            {
                printf("NO\n");return 0;
            }
        }
        if(!hadc.count(x2)){//当二没有选
            hadcs.insert(x2);//单独选x2

            hadc.insert(x1);
            hadc.insert(x2);
            output[i]=x2;
        }
    }
    cout << "YES\n";
    for(i=0;i<n;i++)
        cout << output[i] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
const int maxn=1005;
const int maxl=25;
struct name
{
    string firstchose;
    string secondchose;
}fc[maxn];
string output[maxn];
int main()
{
    int n,i;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        string a, b;
        cin >> a >> b;
        fc[i].firstchose=a.substr(0, 3);
        fc[i].secondchose=a.substr(0, 2)+b.substr(0 ,1);
//        cout << fc[i].firstchose << endl;
//        cout << fc[i].secondchose << endl;
    }

    set <string> hadc;
    set <string> hadcs;
    for(i=0;i<n;i++)
    {
        string x1=fc[i].firstchose;
        string x2=fc[i].secondchose;
        if(hadc.count(x2)){
            if(!hadcs.count(x2)){
                hadcs.insert(x2);
                output[i]=x2;
            }
            else if(!hadc.count(x1))
            {
                hadcs.insert(x1);
                hadc.insert(x1);
                output[i]=x1;
            }
            else{
                printf("NO\n");
                return 0;
            }
        }
        if(!hadc.count(x2)){//当二没有选
            hadcs.insert(x2);//单独选x2

            hadc.insert(x1);
            hadc.insert(x2);
            output[i]=x2;
        }
    }
    cout << "YES\n";
    for(i=n-1;i>=0;i--)
        cout << output[i] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
const int maxn=1005;
const int maxl=25;
struct name
{
    string firstchose;
    string secondchose;
}fc[maxn];
string output[maxn];
int main()
{
    int n,i;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        string a, b;
        cin >> a >> b;
        fc[i].firstchose=a.substr(0, 3);
        fc[i].secondchose=a.substr(0, 2)+b.substr(0 ,1);
//        cout << fc[i].firstchose << endl;
//        cout << fc[i].secondchose << endl;
    }

    set <string> hadc;
    set <string> hadcs;
    for(i=0;i<n;i++)
    {
        string x1=fc[i].firstchose;
        string x2=fc[i].secondchose;
        if(hadc.count(x2)){
            if(!hadcs.count(x2)){
                hadcs.insert(x2);
                output[i]=x2;
            }
            else if(!hadc.count(x1))
            {
                hadcs.insert(x1);
                hadc.insert(x1);
                output[i]=x1;
            }
            else{
                printf("NO\n");
                return 0;
            }
        }
        if(!hadc.count(x2)){//当二没有选
            hadcs.insert(x2);//单独选x2

            hadc.insert(x1);
            hadc.insert(x2);
            output[i]=x2;
        }
    }
    cout << "YES\n";
    //for(i=0;i<n;i++)
      //  cout << output[i] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
using namespace std;
const int maxn=1005;
const int maxl=25;
struct name
{
    string firstchose;
    string secondchose;
}fc[maxn];
string output[maxn];
int main()
{
    int n,i;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        string a, b;
        cin >> a >> b;
        fc[i].firstchose=a.substr(0, 3);
        fc[i].secondchose=a.substr(0, 2)+b.substr(0 ,1);
//        cout << fc[i].firstchose << endl;
//        cout << fc[i].secondchose << endl;
    }

    set <string> hadc;
    for(i=0;i<n;i++)
    {
        string x1=fc[i].firstchose;
        string x2=fc[i].secondchose;
        if(hadc.count(x2)&&hadc.count(x1)){
            printf("NO\n");return 0;
        }
        if(!hadc.count(x2)){//当二没有选
            hadc.insert(x2);
            hadc.insert(x1);
            output[i]=x2;
        }
    }
    cout << "YES\n";
    for(i=0;i<n;i++)
        cout << output[i] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include<map>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e17+1LL;
const double Pi = acos(-1.0);
const int N = 5e6+10, M = 1e3+20, mod = 1e9+7, inf = 2e9+10;

map<string ,int > mp;
map<int ,string> fmp;
int n,cnt,go[N];
char a[N],b[N];
vector<pair<int ,int > > G[N];
vector<int > K;
string ans[N];
int OK[N];
int main() {
    scanf("%d",&n);
    for(int i = 1; i <= n; ++i) {
        scanf("%s%s",a,b);
        string aa = "",bb = "";
        aa += a[0];bb += a[0];
        aa += a[1];bb += a[1];
        aa += a[2];bb += b[0];
        if(!mp[aa]) mp[aa] = ++cnt,fmp[cnt] = aa;
        if(!mp[bb]) mp[bb] = ++cnt,fmp[cnt] = bb;
        G[mp[aa]].push_back(MP(mp[bb],i));
    }
    for(int i = 1; i <= cnt; ++i) {
        if(G[i].size() >= 2) K.push_back(i);
    }

    for(int ii = 0; ii < K.size(); ++ii) {
        int k = K[ii];
        for(int i = 0; i < G[k].size(); ++i) {
            OK[G[k][i].second]++;
            ans[G[k][i].second] = fmp[G[k][i].first];
            go[G[k][i].first]++;
            if(go[G[k][i].first] >= 2) {
                puts("NO");
                return 0;
            }
        }
    }

    for(int i = 1; i <= cnt; ++i) {
        if(G[i].size() == 0) continue;
        if(G[i].size() == 1) {
            if(!go[i])  ans[G[i][0].second] = fmp[i],go[i]++,OK[G[i][0].second]++;
            else if(!go[G[i][0].first]) ans[G[i][0].second] = fmp[G[i][0].first],go[G[i][0].first]++,OK[G[i][0].second]++;
            else {
                puts("NO");
                return 0;
            }
        }
    }
    for(int i = 1; i <= n; ++i) {
        if(!OK[i]) {puts("NO");return 0;}
    }
    cout<<"YES"<<endl;
    for(int i = 1; i <= n; ++i) cout<<ans[i]<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include<map>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e17+1LL;
const double Pi = acos(-1.0);
const int N = 5e5+10, M = 1e3+20, mod = 1e9+7, inf = 2e9+10;

map<string ,int > mp;
map<int ,string> fmp;
int n,cnt;
char a[N],b[N];
vector<pair<int ,int > > G[N];
vector<int > K;
string ans[N];
int main() {
    scanf("%d",&n);;
    for(int i = 1; i <= n; ++i) {
        scanf("%s%s",a,b);
        string aa = "",bb = "";
        aa += a[0];bb += a[0];
        aa += a[1];bb += a[1];
        aa += a[2];bb += b[0];
        if(!mp[aa]) mp[aa] = ++cnt,fmp[cnt] = aa;
        if(!mp[bb]) mp[bb] = ++cnt,fmp[cnt] = bb;
        G[mp[aa]].push_back(MP(mp[bb],i));
        if(G[mp[aa]].size() >= 2) K.push_back(mp[aa]);
    }
    for(int i = 1; i <= cnt; ++i) {
        if(G[i].size() == 0) continue;
        if(G[i].size() == 1) {
            ans[G[i][0].second] = fmp[i];
        }
    }
    for(int ii = 0; ii < K.size(); ++ii) {
        int k = K[ii];
        for(int i = 0; i < G[k].size(); ++i) {
            for(int j = 0; j < G[k].size(); ++j) {
                if(i == j) continue;
                if(G[k][i].first == G[k][j].first) {
                    puts("NO");
                    return 0;
                }
            }
        }
        for(int i = 0; i < G[k].size(); ++i) {
            ans[G[k][i].second] = fmp[G[k][i].first];
        }
    }
    cout<<"YES"<<endl;
    for(int i = 1; i <= n; ++i) cout<<ans[i]<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include<map>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e17+1LL;
const double Pi = acos(-1.0);
const int N = 5e6+10, M = 1e3+20, mod = 1e9+7, inf = 2e9+10;

map<string ,int > mp;
map<int ,string> fmp;
int n,cnt,go[N];
char a[N],b[N];
vector<pair<int ,int > > G[N];
vector<int > K;
string ans[N];
int OK[N];
int main() {
    scanf("%d",&n);
    for(int i = 1; i <= n; ++i) {
        scanf("%s%s",a,b);
        string aa = "",bb = "";
        aa += a[0];bb += a[0];
        aa += a[1];bb += a[1];
        aa += a[2];bb += b[0];
        if(!mp[aa]) mp[aa] = ++cnt,fmp[cnt] = aa;
        if(!mp[bb]) mp[bb] = ++cnt,fmp[cnt] = bb;
        G[mp[aa]].push_back(MP(mp[bb],i));
    }
    for(int i = 1; i <= cnt; ++i) {
        if(G[i].size() >= 2) K.push_back(i);
    }

    for(int ii = 0; ii < K.size(); ++ii) {
        int k = K[ii];
        for(int i = 0; i < G[k].size(); ++i) {
            OK[G[k][i].second]++;
            if(go[G[k][i].first]){
                puts("NO");
                return 0;
            }
            ans[G[k][i].second] = fmp[G[k][i].first];
            go[G[k][i].first]++;
        }
    }

    for(int i = 1; i <= cnt; ++i) {
        if(G[i].size() == 0) continue;
        if(G[i].size() == 1) {
            if(!go[i])  ans[G[i][0].second] = fmp[i],go[i]++,OK[G[i][0].second]++;
            else if(!go[G[i][0].first]) ans[G[i][0].second] = fmp[G[i][0].first],go[G[i][0].first]++,OK[G[i][0].second]++;
            else {
                puts("NO");
                return 0;
            }
        }
    }
    for(int i = 1; i <= n; ++i) {
        if(!OK[i]) {puts("NO");return 0;}
    }
    cout<<"YES"<<endl;
    for(int i = 1; i <= n; ++i) cout<<ans[i]<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include<map>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e17+1LL;
const double Pi = acos(-1.0);
const int N = 5e6+10, M = 1e3+20, mod = 1e9+7, inf = 2e9+10;

map<string ,int > mp;
map<int ,string> fmp;
int n,cnt,go[N];
char a[N],b[N];
vector<pair<int ,int > > G[N];
vector<int > K;
string ans[N];
int OK[N];
int main() {
    scanf("%d",&n);
    for(int i = 1; i <= n; ++i) {
        scanf("%s%s",a,b);
        string aa = "",bb = "";
        aa += a[0];bb += a[0];
        aa += a[1];bb += a[1];
        aa += a[2];bb += b[0];
        if(!mp[aa]) mp[aa] = ++cnt,fmp[cnt] = aa;
        if(!mp[bb]) mp[bb] = ++cnt,fmp[cnt] = bb;
        G[mp[aa]].push_back(MP(mp[bb],i));
    }
    for(int i = 1; i <= cnt; ++i) {
        if(G[i].size() >= 2) K.push_back(i);
    }

    for(int ii = 0; ii < K.size(); ++ii) {
        int k = K[ii];
        for(int i = 0; i < G[k].size(); ++i) {
            OK[G[k][i].second]++;
            if(go[G[k][i].first]){
                puts("NO");
                return 0;
            }
            ans[G[k][i].second] = fmp[G[k][i].first];
            go[G[k][i].first]++;
        }
    }
    while(1) {
        int oK = 0;
        for(int i = 1; i <= cnt; ++i) {
        if(G[i].size() == 1) {
            if(go[i]) {
                if(go[G[i][0].first]) {puts("NO");return 0;}
                ans[G[i][0].second] = fmp[G[i][0].first],go[G[i][0].first]++;
                G[i].pop_back();
                oK = 1;
            }

            }
        }
        if(!oK) break;
    }

    for(int i = 1; i <= cnt; ++i) {
        if(G[i].size() == 0) continue;
        if(G[i].size() == 1) {
            if(!go[i])  ans[G[i][0].second] = fmp[i],go[i]++,OK[G[i][0].second]++;
            else if(!go[G[i][0].first]) ans[G[i][0].second] = fmp[G[i][0].first],go[G[i][0].first]++,OK[G[i][0].second]++;
            else {
                puts("NO");
                return 0;
            }
        }
    }
    cout<<"YES"<<endl;
    for(int i = 1; i <= n; ++i) cout<<ans[i]<<endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    if (a.start < b.start) {
        return true;
    } else if (a.start > b.start) {
        return false;
    } else {
        return a.end > b.end;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    int last = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            last = max(target.end, last);
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    for (int i = 0; i <= last; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start < lastPos) {
            newPos = lastPos - targetSeq.start + 1;
        }
        for (int j = newPos; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    if (a.start < b.start) {
        return true;
    } else if (a.start > b.start) {
        return false;
    } else {
        return a.end > b.end;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    int last = 0;
    int maxStrLen = 0;
    int maxK = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        maxStrLen = max((int)a.size(), maxStrLen);
        int k;
        scanf("%d", &k);
        maxK = max(k ,maxK);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            last = max(target.end, last);
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    if (maxStrLen > 10000) {
        cout << "k: " << maxK << endl;
        cout << maxStrLen << endl;
    }

    for (int i = 0; i <= last; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start <= lastPos) {
            newPos = lastPos - targetSeq.start + 1;
        }
        for (int j = newPos; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[3 * MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    if (a.start < b.start) {
        return true;
    } else if (a.start > b.start) {
        return false;
    } else {
        return a.end > b.end;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    int last = 0;
    int maxStrLen = 0;
    int maxK = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        maxStrLen = max((int)a.size(), maxStrLen);
        int k;
        scanf("%d", &k);
        maxK = max(k ,maxK);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            last = max(target.end, last);
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    /*
    if (maxStrLen > 10000) {
        cout << "k: " << maxK << endl;
        cout << maxStrLen << endl;
    }
    */

    for (int i = 0; i <= last; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start <= lastPos) {
            newPos = lastPos - targetSeq.start + 1;
        }
        for (int j = newPos; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
            /*
            if (maxStrLen > 10000) {
                printf("%d ", targetSeq.start + j);
                printf("%c ", targetChar);
            }
            */
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    if (a.start < b.start) {
        return true;
    } else if (a.start > b.start) {
        return false;
    } else {
        return a.end > b.end;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    int last = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            last = max(target.end, last);
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    for (int i = 0; i <= last; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start < lastPos) {
            newPos = lastPos - targetSeq.start;
        }
        for (int j = newPos; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

char finalString[MAX2];
char inputString[MAX];
struct sequence {
    string s;
    int start;
    int end;
};

bool cmp(struct sequence &a, struct sequence &b) {
    return a.start < b.start;
}

int main() {
    vector<struct sequence> v;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            struct sequence target;
            target.s = inputString;
            target.start = pos;
            target.end = pos + target.s.size() - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        struct sequence targetSeq = v[i];
        //cout << targetSeq.s << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        for (int j = 0; j < targetSeq.s.size(); j++) {
            char targetChar = targetSeq.s[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        lastPos = targetSeq.end;
    }

    //cout << lastPos <<endl;
    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

char finalString[MAX2];
char inputString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;
            string a = inputString;
            stringVector[num] = a;
            num++;
            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.s << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = 0; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        lastPos = targetSeq.end;
    }

    //cout << lastPos <<endl;
    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    for (int i = 0; i < MAX; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start < lastPos) {
            newPos = lastPos - targetSeq.start;
        }
        for (int j = newPos; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
char inputString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    int lastPos = 1;
    for (int i = 0; i < v.size(); i++) {
        lastPos = max(lastPos, v[i].end);
    }
    string finalString = "";

    for (int i = 0; i <= lastPos; i++) {
        finalString += "a";
    }

    lastPos = 1;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = 0; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());

    /*
    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }
    */

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

char finalString[MAX2];
char inputString[MAX];
struct sequence {
    string s;
    int start;
    int end;
};

bool cmp(struct sequence &a, struct sequence &b) {
    return a.start < b.start;
}

int main() {
    vector<struct sequence> v;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            struct sequence target;
            target.s = inputString;
            target.start = pos;
            target.end = pos + target.s.size() - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        struct sequence targetSeq = v[i];
        //cout << targetSeq.s << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        for (int j = 0; j < targetSeq.s.size(); j++) {
            char targetChar = targetSeq.s[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        lastPos = targetSeq.end;
    }

    //cout << lastPos <<endl;
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

struct sequence {
    string s;
    int start;
    int end;
};

bool cmp(struct sequence &a, struct sequence &b) {
    return a.start < b.start;
}

int main() {
    vector<struct sequence> v;
    int n;
    scanf("%d", &n);

    char finalString[MAX2];
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }
    char inputString[MAX];
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            struct sequence target;
            target.s = inputString;
            target.start = pos;
            target.end = pos + target.s.size() - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        struct sequence targetSeq = v[i];
        //cout << targetSeq.s << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        for (int j = 0; j < targetSeq.s.size(); j++) {
            char targetChar = targetSeq.s[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        lastPos = targetSeq.end;
    }

    for (int i = 1; i <= lastPos; i++) {
        printf("%c", finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

char finalString[MAX2];
char inputString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.s << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = 0; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        lastPos = targetSeq.end;
    }

    //cout << lastPos <<endl;
    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

char finalString[MAX2];
char inputString[MAX];
vector<string> stringVector;
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;
            string a = inputString;
            stringVector.push_back(a);
            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = stringVector.size() - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.s << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = 0; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        lastPos = targetSeq.end;
    }

    //cout << lastPos <<endl;
    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    if (a.start < b.start) {
        return true;
    } else if (a.start > b.start) {
        return false;
    } else {
        return a.end > b.end;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    int last = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            last = max(target.end, last);
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    for (int i = 0; i <= last; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start <= lastPos) {
            newPos = lastPos - targetSeq.start + 1;
        }
        for (int j = newPos; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    if (a.start < b.start) {
        return true;
    } else if (a.start > b.start) {
        return false;
    } else {
        return a.end > b.end;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    int last = 0;
    int maxStrLen = 0;
    int maxK = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        maxStrLen = max((int)a.size(), maxStrLen);
        int k;
        scanf("%d", &k);
        maxK = max(k ,maxK);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            last = max(target.end, last);
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    if (maxStrLen > 10000) {
        cout << "k: " << maxK << endl;
        cout << maxStrLen << endl;
    }

    for (int i = 0; i <= last; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start <= lastPos) {
            newPos = lastPos - targetSeq.start + 1;
        }
        for (int j = newPos; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
            if (maxStrLen > 10000) {
                printf("%d ", targetSeq.start + j);
                printf("%c ", targetChar);
            }
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    for (int i = 0; i < MAX; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 1;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = 0; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    for (int i = 0; i < MAX; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = lastPos + 1; j <= targetSeq.end; j++) {
            char targetChar = targetString[j - targetSeq.start];
            finalString[j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

char finalString[MAX2];
char inputString[MAX];
typedef struct sequence {
    string s;
    int start;
    int end;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;
            target.s = inputString;
            target.start = pos;
            target.end = pos + target.s.size() - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.s << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        for (int j = 0; j < targetSeq.s.size(); j++) {
            char targetChar = targetSeq.s[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        lastPos = targetSeq.end;
    }

    //cout << lastPos <<endl;
    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

char finalString[MAX2];
char inputString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 1;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = 0; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());

    /*
    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }
    */

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    int last = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            last = max(target.end, last);
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    for (int i = 0; i <= last; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start < lastPos) {
            newPos = lastPos - targetSeq.start;
        }
        for (int j = newPos; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[3 * MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    if (a.start < b.start) {
        return true;
    } else if (a.start > b.start) {
        return false;
    } else {
        return a.end > b.end;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    int last = 0;
    int maxStrLen = 0;
    int maxK = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        maxStrLen = max((int)a.size(), maxStrLen);
        int k;
        scanf("%d", &k);
        maxK = max(k ,maxK);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            last = max(target.end, last);
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    /*
    if (maxStrLen > 10000) {
        cout << "k: " << maxK << endl;
        cout << maxStrLen << endl;
    }
    */

    for (int i = 0; i <= last; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 0;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        //string targetString = stringVector[targetSeq.index];
        int newPos = 0;
        if (targetSeq.start <= lastPos) {
            newPos = lastPos - targetSeq.start + 1;
        }
        for (int j = newPos; j < stringVector[targetSeq.index].size(); j++) {
            char targetChar = stringVector[targetSeq.index][j];
            finalString[targetSeq.start + j] = targetChar;
            /*
            if (maxStrLen > 10000) {
                printf("%d ", targetSeq.start + j);
                printf("%c ", targetChar);
            }
            */
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    /*
    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());
    */

    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 100010
#define MAX2 1000010

char finalString[MAX2];
char inputString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < MAX2; i++) {
        finalString[i] = 'a';
    }

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);
    int lastPos = 1;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.s << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = 0; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        lastPos = targetSeq.end;
    }

    //cout << lastPos <<endl;

    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());

    /*
    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }
    */

}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <iterator>
#include <algorithm>
#include <utility>
#include <cassert>
#include <sstream>
using namespace std;

#define MAX 1000100
char inputString[MAX];
char finalString[MAX];
string stringVector[MAX];
typedef struct sequence {
    int start;
    int end;
    int index;
} sequence;
vector<sequence> v;

bool cmp(sequence &a, sequence &b) {
    return a.start < b.start;
}

int main() {
    int n;
    scanf("%d", &n);

    int num = 0;
    for (int i = 0; i < n ; i++) {
        scanf("%s", inputString);
        string a = inputString;
        stringVector[num] = a;
        num++;
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int pos;
            scanf("%d", &pos);
            sequence target;

            target.start = pos;
            target.end = pos + a.size() - 1;
            target.index = num - 1;
            v.push_back(target);
        }
    }
    sort(v.begin(), v.end(), cmp);

    for (int i = 0; i < MAX; i++) {
        finalString[i] = 'a';
    }

    int lastPos = 1;
    for (int i = 0; i < v.size(); i++) {
        sequence targetSeq = v[i];
        //cout << targetSeq.start << endl;
        if (targetSeq.end <= lastPos) {
            continue;
        }
        string targetString = stringVector[targetSeq.index];
        for (int j = 0; j < targetString.size(); j++) {
            char targetChar = targetString[j];
            finalString[targetSeq.start + j] = targetChar;
        }
        if (targetSeq.end > lastPos) {
            lastPos = targetSeq.end;
        }
    }

    //cout << lastPos <<endl;

    string final = finalString;
    final = final.substr(1, lastPos);

    printf("%s", final.c_str());

    /*
    for (int i = 1; i <= lastPos; i++) {
        putchar(finalString[i]);
    }
    */

}


#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
#define fin(name) freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
typedef pair<int, int> pii;
typedef long long LL;
const double PI = acos(-1.0);
const int N = 1e5 + 10;
const int M = 2e6 + 10;
const int BC = 1420;
struct Block
{
	int l, r;
	int id, st;
};
struct info
{
	int rst;
	int len;
};
info S[N];
char str[1000010];
Block B[BC];
int belong[M], unit, bcnt, maxlen;
pii arr[M];
vector<int>ST[N];

void init()
{
	bcnt = maxlen / unit;
	if (maxlen % unit)
		++bcnt;
	int i;
	for (i = 1; i <= bcnt; ++i)
	{
		B[i].l = (i - 1) * unit + 1;
		B[i].r = i * unit;
		B[i].id = -1;
		B[i].st = 1;
	}
	B[bcnt].r = maxlen;
	for (i = 1; i <= maxlen; ++i)
		belong[i] = (i - 1) / unit + 1;
}
inline void pushdown(int bx)
{
	if(B[bx].id!=-1)
	{
		for (int i=B[bx].l; i<=B[bx].r; ++i)
			arr[i].first=B[bx].id, arr[i].second=B[bx].st;
		B[bx].id=-1;
		B[bx].st=1;
	}
}
void update(int l, int r, int id, int st)
{
	int bl = belong[l], br = belong[r];
	if (bl == br)
	{
		pushdown(bl);
		for (int i = l; i <= r; ++i)
			arr[i].first = id, arr[i].second = st;
	}
	else
	{
		pushdown(bl);
		pushdown(br);
		for (int i = l; i <= B[bl].r; ++i)
			arr[i].first = id, arr[i].second = st;
		for (int i = B[br].l; i <= r; ++i)
			arr[i].first = id, arr[i].second = st;
		for (int i = bl + 1; i < br; ++i)
			B[i].id = id, B[i].st = st;
	}
}
pii query(int x)
{
	int bx = belong[x];
	pushdown(bx);
	return arr[x];
}
int main(void)
{
	int n, k, i;
	while (~scanf("%d", &n))
	{
		maxlen = 0;
		int idx=1;
		for (i = 1; i <= n; ++i)
		{
			scanf("%s",str+idx);
			S[i].len = strlen(str+idx);
			S[i].rst=idx;
			scanf("%d", &k);
			while (k--)
			{
				int _st;
				scanf("%d", &_st);
				ST[i].push_back(_st);
				maxlen = max(maxlen, S[i].len + _st - 1);
			}
			idx+=S[i].len;
		}
		unit = sqrt(maxlen);
		init();
		for (i = 1; i <= n; ++i)
		{
			int sz = ST[i].size();
			for (int j = 0; j < sz; ++j)
				update(ST[i][j], ST[i][j] + S[i].len - 1, i, ST[i][j]);
		}
		for (i = 1; i <= maxlen; ++i)
		{
			pii c = query(i);
			if (c.first == 0)
				putchar('a');
			else
			{
				int start = S[c.first].rst;
				printf("%c", str[start+i-c.second]);
			}
		}
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
#define fin(name) freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int N=1e5;
const int M=2e6+7;
const int BC=1010;
struct Block
{
    int l,r;
    int id,st;
};
struct info
{
    string s;
    int st,len;
};
info S[N];
Block B[BC];
int belong[M],unit,bcnt,maxlen;
pii arr[1000010];
vector<int>ST[N];

void init()
{
    bcnt=maxlen/unit;
    if(maxlen%unit)
        ++bcnt;
    int i;
    for (i=1; i<=bcnt; ++i)
    {
        B[i].l=(i-1)*unit+1;
        B[i].r=i*unit;
        B[i].id=-1;
    }
    B[bcnt].r=maxlen;
    for (i=1; i<=maxlen; ++i)
        belong[i]=(i-1)/unit+1;
}
void update(int l,int r,int id,int st)
{
    int bl=belong[l],br=belong[r];
    if(bl==br)
    {
        for (int i=l; i<=r; ++i)
            arr[i].first=id,arr[i].second=st;
        B[bl].id=-1;
    }
    else
    {
        B[bl].id=-1;
        B[br].id=-1;
        for (int i=l; i<=B[bl].r; ++i)
            arr[i].first=id,arr[i].second=st;
        for (int i=B[br].l; i<=r; ++i)
            arr[i].first=id,arr[i].second=st;
        for (int i=bl+1; i<br; ++i)
            B[i].id=id, B[i].st=st;
    }
}
pii query(int x)
{
    int bx=belong[x];
    if(B[bx].id!=-1)
        return pii(B[bx].id,B[bx].st);
    else
        return arr[x];
}
int main(void)
{
    int n,k,i;
    while (~scanf("%d",&n))
    {
        maxlen=0;
        for (i=1; i<=n; ++i)
        {
            cin>>S[i].s;
            S[i].len=S[i].s.size();
            scanf("%d",&k);
            while (k--)
            {
                scanf("%d",&S[i].st);
                ST[i].push_back(S[i].st);
                maxlen=max(maxlen,S[i].len+S[i].st-1);
            }
        }
        unit=sqrt(maxlen);
        init();
        for (i=1; i<=n; ++i)
        {
            int sz=ST[i].size();
            for (int j=0; j<sz; ++j)
            {
                update(ST[i][j],ST[i][j]+S[i].len-1,i,ST[i][j]);
            }
        }
        for (i=1; i<=maxlen; ++i)
        {
            pii c=query(i);
            if(c.first==0)
                putchar('a');
            else
                printf("%c",S[c.first].s[i-c.second]);
        }
        puts("");
    }
    return 0;
}