#include <bits/stdc++.h>
int N, M, Q;
std::map<std::string, int> id;
int f[100001], d[100001];
int F(int x) {
  if (f[x] == x)
    return x;
  else {
    F(f[x]);
    d[x] ^= d[f[x]];
    return f[x] = f[f[x]];
  }
}
int main() {
  scanf("%d%d%d", &N, &M, &Q);
  for (int i = 1; i <= N; i++) {
    std::string x;
    std::cin >> x;
    id[x] = i;
    f[i] = i;
  }
  for (int i = 1; i <= M; i++) {
    int op;
    std::string x, y;
    std::cin >> op >> x >> y;
    int u = id[x], v = id[y], fu = F(u), fv = F(v);
    if (fu == fv) {
      if ((op == 1) == (d[u] == d[v]))
        puts("YES");
      else
        puts("NO");
    } else {
      puts("YES");
      f[fv] = fu;
      d[fv] = d[u] ^ d[v] ^ (op == 2);
    }
  }
  for (int i = 1; i <= Q; i++) {
    std::string x, y;
    std::cin >> x >> y;
    int u = id[x], v = id[y];
    if (F(u) != F(v))
      puts("3");
    else if (d[u] == d[v])
      puts("1");
    else
      puts("2");
  }
  return 0;
}
