#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int n, m, p;
string s[maxn];
map<string, int> H;
int fa[maxn];
int fi(int x) { return fa[x] == x ? x : fa[x] = fi(fa[x]); }
void uni(int x, int y) {
  x = fi(x), y = fi(y);
  if (x != y) fa[x] = y;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 1; i <= 2 * n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    H[s[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    int op;
    string a, b;
    cin >> op >> a >> b;
    int id1 = H[a], id2 = H[b];
    if (op == 1) {
      if (fi(id1 * 2) == fi(id2 * 2 - 1)) {
        cout << "NO" << endl;
        continue;
      }
      if (fi(id1 * 2 - 1) == fi(id2 * 2)) {
        cout << "NO" << endl;
      }
      cout << "YES" << endl;
      uni(id1 * 2, id2 * 2);
      uni(id1 * 2 - 1, id2 * 2 - 1);
    } else {
      if (fi(id1 * 2) == fi(id2 * 2)) {
        cout << "NO" << endl;
        continue;
      }
      if (fi(id1 * 2 - 1) == fi(id2 * 2 - 1)) {
        cout << "NO" << endl;
      }
      cout << "YES" << endl;
      uni(id1 * 2, id2 * 2 - 1);
      uni(id1 * 2 - 1, id2 * 2);
    }
  }
  for (int i = 1; i <= p; i++) {
    string a, b;
    cin >> a >> b;
    int id1 = H[a], id2 = H[b];
    if (fi(2 * id1) == fi(2 * id2))
      cout << "1" << endl;
    else if (fi(2 * id1 - 1) == fi(2 * id2 - 1))
      cout << "1" << endl;
    else if (fi(2 * id1 - 1) == fi(2 * id2))
      cout << "2" << endl;
    else if (fi(2 * id1) == fi(2 * id2 - 1))
      cout << "2" << endl;
    else
      cout << "3" << endl;
  }
}
