#include<iostream>
#include<string>
#include<vector>
#include<queue>
using namespace std;

const int pow26[] = { 1, 26, 26 * 26, 26 * 26 * 26 };
vector<int> pat[460000];
vector<int> graph[100010];
int inDegree[100010];
int n, m, k;

int str2int(const string& str) {
	int res = 0;
	for (int i = 0; i < k; ++i) {
		res += pow26[k - i - 1] * (str[i] - 'a');
	}
	return res;
}

void addPat(string& pattern, int ind, int j) {
	if (j == k) {
		pat[str2int(pattern)].push_back(ind);
		return;
	}
	if (pattern[j] == '_') {
		for (char c = 'a'; c <= 'z'; c++) {
			pattern[j] = c;
			addPat(pattern, ind, j + 1);
		}
		pattern[j] = '_';
	}
	else addPat(pattern, ind, j + 1);
}

int main() {
	cin >> n >> m >> k;
	string t;
	getline(cin, t);
	for (int i = 1; i <= n; ++i) {
		getline(cin, t);
		addPat(t, i, 0);
	}
	int pm;
	for (int i = 1; i <= m; ++i) {
		cin >> t >> pm;
		int num = str2int(t);
		bool ok = 0;
		for (int node : pat[num]) {
			if (node == pm) ok = 1;
			else {
				graph[pm].push_back(node);
				inDegree[node]++;
			}
		}
		if (!ok) {
			cout << "NO\n";
			return 0;
		}
	}

	queue<int> output, q;
	for (int i = 1; i <= n; ++i)
		if (inDegree[i] == 0) q.push(i);
	while (!q.empty()) {
		int cur = q.front(); q.pop();
		output.push(cur);
		for (int node : graph[cur]) {
			if (--inDegree[node] == 0) q.push(node);
		}
	}
	if (output.size() == n) {
		cout << "YES\n";
		while (!output.empty()) {
			cout << output.front() << " ";
			output.pop();
		}
		cout << endl;
	}
	else cout << "NO\n";
	return 0;
}
