#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<endl
#define de_arr(a,s,t) cout<<#a<<": ";for (int z=(s);z<=(t);++z)cout<<a[z]<<" ";cout<<endl;
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const double eps=1e-8;
const int mod=1e9+7;
inline int sign(double x){return (x>eps)-(x<-eps);}
inline int add(int a,int b){a+=b;return a<0?a+mod:a>=mod?a-mod:a;}
inline int mul(ll a,ll b){return a*b%mod;}
const int maxn=2e5+10,INF=0x3f3f3f3f;
char p[maxn][10],s[maxn][10];
int pos[maxn],deg[maxn];
vector<int> e[maxn];
int tr[maxn*5][28],idx[maxn*5],tim;
void upd(int id,int k){
	int now=0;
	for (int i=1;i<=k;++i){
		int c=isalpha(p[id][i])?p[id][i]-'a':26;
		if (!tr[now][c])	tr[now][c]=++tim;
		now=tr[now][c];
	}
	idx[now]=id;
}
void qry(int id,int pp,int k,int now,vector<int>& buf){
	if (pp>k){
		buf.pb(idx[now]);
		return;
	}
	int c=s[id][pp]-'a';
	if (tr[now][c])
		qry(id,pp+1,k,tr[now][c],buf);
	if (tr[now][26])
		qry(id,pp+1,k,tr[now][26],buf);
}
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for (int i=1;i<=n;++i){
		scanf("%s",p[i]+1);
		upd(i,k);
		//de(p[i]+1); 
	}
	for (int i=1;i<=m;++i){
		scanf("%s%d",s[i]+1,&pos[i]);
		vector<int> buf;
		qry(i,1,k,0,buf);
		int ok=0;
		for (auto id:buf){
			//de(id);
			if (id==pos[i])	ok=1;
			else	e[pos[i]].pb(id),deg[id]++;
		}
		if (!ok){
			cout<<"NO";
			return 0;
		}
	}
	vector<int> ans;
	queue<int> q;
	for (int i=1;i<=n;++i)
		if (deg[i]==0)
			q.push(i);
	while (sz(q)){
		int u=q.front();
		q.pop();
		ans.pb(u);
		for (auto v:e[u]){
			deg[v]--;
			if (deg[v]==0)
				q.push(v);
		}
	}
	if (sz(ans)<n)	cout<<"NO";
	else{
		cout<<"YES\n";
		for (int i=0;i<n;++i)
			printf("%d%c",ans[i]," \n"[i==n-1]);
	}
	return 0;
}
