#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int, pi> pii;

const int maxn = 100010;
const int INF = LLONG_MAX/2;
const int mod = 1e9+7;

vector <int> adjlist[maxn];
map <string, int> mp;

int canstart[maxn];
//int rans[maxn];
int vis[maxn];
vector <int> ans;

void dfs(int x) {
	vis[x] = 1;
	//cout << x << "\n";
	for (auto i:adjlist[x]) {
		if (vis[i] == 1) {
			cout << "NO";
			exit(0);
		} else if (vis[i] == 2) continue;
		dfs(i);
	}
	vis[x] = 2;
	ans.push_back(x);
}

int32_t main() {
	//FAST
	int n, m, k; cin >> n >> m >> k;
	
	vector <string> p(n+1);
	
	for (int i =1;i<=n;i++) {
		cin >> p[i];
		mp[p[i]] = i;
	}
	
	for (int i =0;i<m;i++) {
		string s; int x;
		cin >> s >> x;
		
		//cout << "HELLO\n";
		for (int j=0;j<k;j++) {
			if (p[x][j] != '_' and p[x][j] != s[j]) {
				cout << "NO";
				exit(0);
			}
		}
		
		for (int bm = 0;bm < (1<<k);bm++) {
			string cur = "";
			for (int j = 0; j < k;j++) {
				if (bm & (1<<j)) cur += s[j];
				else cur += '_';
			}
			if (cur == p[x]) continue;
			
			if (mp.find(cur) != mp.end()) {
				int u = mp[cur];
				adjlist[x].push_back(u);
				canstart[u] = 1;
			}
		}
	}
	
	//for (int i =1;i<=n;i++) {
		//cout << i << ": ";
		//for (auto j:adjlist[i]) cout << j << " ";
		//cout << "\n";
	//}
	
	for (int i =1;i<=n;i++) {
		if (canstart[i] == 0 and !vis[i]) {
			dfs(i);
		}
	}
	
	for (int i =1;i<=n;i++) if (!vis[i]) {
		cout << "NO";
		exit(0);
	}
	
	//for (auto i:ans) cout << i << " ";
	//cout << "\n";
	
	reverse(all(ans));

	cout << "YES\n";
	for (int i =0;i<n;i++) {
		cout << ans[i] << " ";
	}
}



