#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 1e5 + 5;
map<string, int> NAME;
char name[MAXN][22];
int p[MAXN];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void uni(int x, int y) {
  int px = find(x), py = find(y);
  if (px == py) return;
  p[px] = py;
}
int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; i++) {
    scanf("%s", name[i]);
    NAME[name[i]] = i + 1;
  }
  for (int i = 1; i <= 2 * n; i++) p[i] = i;
  int f;
  char s1[22], s2[22];
  for (int i = 0; i < m; i++) {
    scanf("%d%s%s", &f, s1, s2);
    int u = NAME[s1], v = NAME[s2];
    if (f == 1) {
      if (find(u * 2) == find(v * 2 - 1))
        puts("NO");
      else {
        puts("YES");
        uni(u * 2, v * 2);
        uni(u * 2 - 1, v * 2 - 1);
      }
    } else {
      if (find(u * 2) == find(v * 2))
        puts("NO");
      else {
        puts("YES");
        uni(v * 2, u * 2 - 1);
        uni(u * 2, v * 2 - 1);
      }
    }
  }
  while (q--) {
    scanf("%s%s", s1, s2);
    int u = NAME[s1], v = NAME[s2];
    if (find(2 * u) == find(2 * v))
      puts("1");
    else if (find(2 * u) == find(2 * v - 1))
      puts("2");
    else
      puts("3");
  }
  return 0;
}
