#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 7 << 1;
int f[MAXN];
map<string, int> mp;
int findFa(int x) {
  int r = x;
  while (r != f[r]) r = f[r];
  int k = x;
  while (k != r) {
    int j = f[k];
    f[k] = r;
    k = j;
  }
  return r;
}
void unionSet(int a, int b) {
  a = findFa(a);
  b = findFa(b);
  if (a != b) f[b] = a;
  ;
}
int main() {
  int n, m, q;
  char s1[27], s2[27];
  while (scanf("%d %d %d", &n, &m, &q) != EOF) {
    mp.clear();
    for (int i = 1; i <= n; ++i) {
      scanf("%s", s1);
      mp[s1] = i;
      f[i] = i, f[i + n] = i + n;
    }
    int op;
    while (m--) {
      scanf("%d %s %s", &op, s1, s2);
      int x = mp[s1];
      int y = mp[s2];
      if (op == 1) {
        if (findFa(x) == findFa(y + n)) {
          puts("NO");
          continue;
        }
        puts("YES");
        unionSet(x, y);
        unionSet(x + n, y + n);
      } else {
        if (findFa(x) == findFa(y)) {
          puts("NO");
          continue;
        }
        puts("YES");
        unionSet(x, y + n);
        unionSet(x + n, y);
      }
    }
    while (q--) {
      scanf("%s %s", s1, s2);
      int x = mp[s1];
      int y = mp[s2];
      if (findFa(x) == findFa(y))
        puts("1");
      else if (findFa(x + n) == findFa(y))
        puts("2");
      else
        puts("3");
    }
  }
  return 0;
}
