#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int node[N][2], p[N], nodes, n, m, q;
map<string, int> mp;
int get_node(int x, int y) { return node[x][y]; }
int find_set(int x) { return p[x] == x ? x : p[x] = find_set(p[x]); }
void union_sets(int x, int y) {
  x = find_set(x);
  y = find_set(y);
  p[x] = y;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> q;
  for (int i = 1; i <= n; ++i) {
    node[i][0] = ++nodes;
    node[i][1] = ++nodes;
  }
  for (int i = 1; i <= nodes; ++i) p[i] = i;
  for (int i = 1; i <= n; ++i) {
    string s;
    cin >> s;
    mp[s] = i;
  }
  int cnt = 0;
  for (int i = 1; i <= m; ++i) {
    int x;
    string s, t;
    cin >> x >> s >> t;
    int A = mp[s];
    int B = mp[t];
    --x;
    bool ok = true;
    for (int a = 0; a < 2; ++a) {
      if (find_set(get_node(A, a)) == find_set(get_node(B, a ^ x ^ 1))) {
        ok = false;
      }
    }
    if (ok) {
      cout << "YES\n";
      for (int a = 0; a < 2; ++a) {
        union_sets(get_node(A, a), get_node(B, a ^ x));
      }
    } else {
      cout << "NO\n";
    }
  }
  for (int _ = 0; _ < q; ++_) {
    string s, t;
    cin >> s >> t;
    int A = mp[s];
    int B = mp[t];
    bool ok[] = {0, 0};
    for (int x = 0; x < 2; ++x) {
      for (int a = 0; a < 2; ++a) {
        if (find_set(get_node(A, a)) == find_set(get_node(B, a ^ x))) {
          ok[x] = true;
        }
      }
    }
    assert(!ok[0] || !ok[1]);
    if (ok[0]) {
      cout << "1\n";
    } else if (ok[1]) {
      cout << "2\n";
    } else {
      cout << "3\n";
    }
  }
}
