#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
#include <string>
#include <ctime>
#include <chrono>
#include <random>
using namespace std;


//author: Legendary Grandmaster mshiladityam
//This is too simple!
//I completely misunderstood!
//I thought that after the rearrangement the first pattern the j-th string matches in the new pattern permutation is p[mtj]
// But actually, it is in the old original permutation

const int MAX=6e5;

int pos[MAX+1]={0}; //index of pattern string
bool is[MAX+1]={false};

int power2[5]={0};
int power[4]={0};

vector<int> adj[MAX+1];

int hash_it(string s)
{
	int res=0;
	for (int j=0; j<(int)s.size(); j++)
	{
		if (s[j]=='_') continue;
		else
		{
			res+=power[j]*((s[j]-'a')+1);
		}
	}
	return res;
}


int col[MAX+1]={0};

void DFS1(int v)
{
	col[v]=1;
	for (auto u: adj[v])
	{
		if (col[u]==0)
		{
			DFS1(u);		
		}
		else if (col[u]==1)
		{
			cout<<"NO\n";
			exit(0);
		}	
	}
	col[v]=2;
}

int vis[MAX+1]={0};
vector<int> perm;


void DFS(int v) 
{
    vis[v] = true;
    for (int u : adj[v]) 
	{
        if (!vis[u])
		{
            DFS(u);
		}
    }
    perm.push_back(v);
}

void solve()
{
	int n, m, k;
	cin>>n>>m>>k;
	
	for (int j=1; j<=n; j++)
	{
		string p;
		cin>>p;	
		is[hash_it(p)]=true;
		pos[hash_it(p)]=j;		
	}
	
	bool ok=true;
	
	for (int j=1; j<=m; j++)
	{
		string s;
		cin>>s;
		int mt;
		cin>>mt;	
		
		bool foo=false;
		
		vector<int> v;
		
		for (int mask=0; mask<=15; mask++)
		{
			int hash=0;
			for (int i=0; i<k; i++)
			{
				if (mask&power2[i])
				{
					hash+=power[i]*((s[i]-'a')+1);
				}
			}
			if (is[hash])
			{
				if (pos[hash]==mt)
				{
					foo=true;
				}
				v.push_back(pos[hash]);
			}
		}	
		ok&=foo;
		for (auto i: v)
		{
			if (i!=mt)
			{
				adj[mt].push_back(i);
			}
		}	
	}
	if (!ok)
	{
		cout<<"NO\n";
		return;
	}
	
	for (int j=1; j<=n; j++)
	{
		if (col[j]==0)
		{
			DFS1(j);
		}
	}
	cout<<"YES\n";
	
	for (int j=1; j<=n; j++)
	{
		if (!vis[j]) DFS(j);
	}
	reverse(perm.begin(), perm.end());
	for (auto i: perm) cout<<i<<" ";
	return;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	int t;
	//cin >> t;
	t=1;
	
	power[0]=1;
	for (int j=1; j<4; j++) power[j]=power[j-1]*27;
	
	power2[0]=1;
	for (int j=1; j<5; j++) power2[j]=power2[j-1]*2;
	
	while (t--)
	{
		solve();
	}
	return 0;
}