#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 7 << 1;
map<string, int> mp;
int f[MAXN];
char s1[27], s2[27];
int findFa(int x) { return x == f[x] ? x : f[x] = findFa(f[x]); }
void unionSet(int x, int y) {
  x = findFa(x);
  y = findFa(y);
  if (x != y) f[x] = y;
}
int main() {
  int n, m, q;
  while (scanf("%d %d %d", &n, &m, &q) != EOF) {
    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;
}
