//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int maxn = 2e5*16+10;
const int maxm = maxn*2;
int head[maxn],deg[maxn];
int n,m,k;
int cnt;
struct Edge{
	int f,t,next;
	Edge(int f = 0,int t = 0,int next = 0):f(f),t(t),next(next){}
}edge[maxm];
void addedge(int f,int t){
	edge[cnt] = Edge(f,t,head[f]);
	head[f] = cnt++;
}
bool check(string p,string t){
	bool ok = 1;
	for(int i = 0;i < k;i++)if(p[i] != '_' and p[i] != t[i])ok = 0;
	return ok;
}
map<string,int>idx;
string patt[maxn];
vector<int>topo;
bool toposort(){
	int count = 0;
	queue<int>q;
	for(int i = 1;i <= n;i++)if(!deg[i]){
		q.push(i);
		count++;
	}
	while(!q.empty()){
		int u = q.front();
		topo.push_back(u);
		q.pop();
		for(int i = head[u];~i;i = edge[i].next){
			int v = edge[i].t;
			deg[v]--;
			if(deg[v] == 0){
				q.push(v);
				count++;
			}
		}
	}
	if(count == n)return 1;
	else return 0;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset(head,-1,sizeof(head));
	cin >> n >> m >> k;
	for(int i = 1;i <= n;i++){
		string s;
		cin >> s;
		patt[i] = s;
		idx[s] = i;
	}
	bool ok = 1;
	for(int i = 1;i <= m;i++){
		string s;
		int u;
		cin >> s >> u;
		if(!check(patt[u],s)){
			cout << "NO";
			exit(0);
		}
		for(int i = 0;i < (1<<k);i++){
			string tmp;
			for(int j = 0;j < k;j++){
				if((i>>j)&1)tmp += s[j];
				else tmp += '_';
			}
			int v = -1;
			if(idx.count(tmp))v = idx[tmp];
			if(v != -1 and v != u){
				addedge(u,v);
				deg[v]++;
			}
		}
	}
	if(!toposort())ok = 0;
	if(ok){
		cout << "YES\n";
		for(int x:topo)cout << x << " ";
	}
	else cout << "NO\n";
	return 0;
}
