#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int f[200200];
int dis[200200];
int find(int x) {
  if (f[x] == x) return x;
  return f[x] = find(f[x]);
}
int main() {
  int n, m, q;
  while (~scanf("%d %d %d", &n, &m, &q)) {
    mp.clear();
    memset(dis, -1, sizeof(dis));
    string s;
    for (int i = 1; i <= n; ++i) {
      cin >> s;
      mp[s] = i;
      f[i] = i;
    }
    for (int i = 0; i < m; ++i) {
      string s1, s2;
      int rel;
      cin >> rel >> s1 >> s2;
      int u = mp[s1], v = mp[s2];
      int fu = find(u), fv = find(v);
      if (rel == 1) {
        if (dis[fu] == fv) {
          printf("NO\n");
          continue;
        }
        if (fu == fv) {
          printf("YES\n");
          continue;
        }
        f[fv] = fu;
        if (dis[fu] == -1 && dis[fv] != -1) {
          dis[fu] = dis[fv];
          dis[dis[fv]] = fu;
        } else if (dis[fu] != dis[fv] && dis[fu] != -1 && dis[fv] != -1) {
          f[dis[fv]] = dis[fu];
          dis[dis[fv]] = -1;
        }
        dis[fv] = -1;
        printf("YES\n");
      }
      if (rel == 2) {
        if (fu == fv) {
          printf("NO\n");
          continue;
        }
        if (dis[fu] != -1 && dis[fu] != fv) {
          int tmp = dis[fu];
          dis[fu] = f[dis[fu]] = fv;
          dis[tmp] = -1;
        } else
          dis[fu] = fv;
        if (dis[fv] != -1 && dis[fv] != fu) {
          int tmp = dis[fv];
          dis[fv] = f[dis[fv]] = fu;
          dis[tmp] = -1;
        } else
          dis[fv] = fu;
        printf("YES\n");
      }
    }
    while (q--) {
      string s1, s2;
      cin >> s1 >> s2;
      int u = mp[s1], v = mp[s2];
      int fu = find(u), fv = find(v);
      if (fu == fv)
        printf("1\n");
      else if (dis[fu] == fv)
        printf("2\n");
      else
        printf("3\n");
    }
  }
}
