#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2;
struct node {
  int pre;
  int realtion;
} f[maxn];
map<string, int> mp;
int find(int x) {
  if (f[x].pre == -1) return x;
  int tmp = f[x].pre;
  f[x].pre = find(tmp);
  f[x].realtion = (f[x].realtion + f[tmp].realtion) % 2;
  return f[x].pre;
}
int main() {
  int n, m, q, i, j, k, x, y, z, fx, fy, ans, cnt;
  string s, s1, s2;
  while (scanf("%d%d%d", &n, &m, &q) != EOF) {
    mp.clear();
    for (i = 1; i <= n; i++) {
      cin >> s;
      mp[s] = i;
    }
    for (i = 1; i <= n; i++) {
      f[i].pre = -1;
      f[i].realtion = 0;
    }
    for (i = 1; i <= m; i++) {
      cin >> k >> s1 >> s2;
      k--;
      x = mp[s1];
      y = mp[s2];
      fx = find(x);
      fy = find(y);
      if (fx == fy) {
        if ((f[x].realtion == f[y].realtion && !k) ||
            (f[x].realtion != f[y].realtion && k))
          printf("YES\n");
        else
          printf("NO\n");
      } else {
        f[fy].pre = fx;
        f[fy].realtion = abs(f[x].realtion + k - f[y].realtion) % 2;
        printf("YES\n");
      }
    }
    for (i = 1; i <= q; i++) {
      cin >> s1 >> s2;
      x = mp[s1];
      y = mp[s2];
      fx = find(x);
      fy = find(y);
      if (fx != fy)
        printf("3\n");
      else
        printf("%d\n", abs(-f[y].realtion + f[x].realtion) + 1);
    }
  }
  return 0;
}
