#include <bits/stdc++.h>
const double Pi = 3.1415926;
const int mod = 1e9 + 7;
const int maxn = 100005;
const int INF = 1e18;
using namespace std;
int pre[2 * maxn], n, m, q, op;
char str[maxn][25], str1[25], str2[25];
void init(int n) {
  for (int i = 0; i < n; i++) {
    pre[i] = i;
    pre[i + n] = i + n;
  }
}
int Find(int x) {
  if (pre[x] == x)
    return x;
  else
    return pre[x] = Find(pre[x]);
}
bool same(int x, int y) { return Find(x) == Find(y); }
map<string, int> mp;
int main() {
  while (~scanf("%d%d%d", &n, &m, &q)) {
    mp.clear();
    int x, y;
    for (int i = 0; i < n; i++) {
      scanf("%s", str[i]);
      mp[str[i]] = i;
    }
    init(n);
    for (int i = 0; i < m; i++) {
      bool flag = 0;
      scanf("%d%s%s", &op, str1, str2);
      x = mp[str1];
      y = mp[str2];
      if (op == 1) {
        if (same(x, y + n) || same(x + n, y))
          printf("NO\n");
        else {
          printf("YES\n");
          pre[Find(x)] = pre[Find(y)];
          pre[Find(x + n)] = pre[Find(y + n)];
        }
      } else if (op == 2) {
        if (same(x, y) || same(x + n, y + n))
          printf("NO\n");
        else {
          printf("YES\n");
          pre[Find(x + n)] = pre[Find(y)];
          pre[Find(x)] = pre[Find(y + n)];
        }
      }
    }
    for (int i = 0; i < q; i++) {
      int ans = 0;
      scanf("%s%s", str1, str2);
      x = mp[str1];
      y = mp[str2];
      if (same(x, y) || same(x + n, y + n)) {
        ans = 1;
      } else if (same(x, y + n) || same(x + n, y)) {
        ans = 2;
      } else
        ans = 3;
      printf("%d\n", ans);
    }
  }
  return 0;
}
