#include <bits/stdc++.h>
using namespace std;
map<string, int> id;
int nxt = 1;
int dsu[int(1e5 + 5)];
int Find(int x) { return dsu[x] == x ? x : dsu[x] = Find(dsu[x]); }
int Union(int x, int y) { return dsu[Find(x)] = Find(y); }
int opp[int(1e5 + 5)];
int main() {
  std::ios::sync_with_stdio(false);
  int n, m, q;
  scanf("%d%d%d", &(n), &(m), &(q));
  for (long long i = 1, __R = n; i <= __R; i++) {
    static char buf[25];
    scanf("%s", buf);
    if (!id.count(buf)) id[buf] = nxt++;
    dsu[i] = i;
  }
  for (long long i = 1, __R = m; i <= __R; i++) {
    int t;
    scanf("%d", &(t));
    static char x[25], y[25];
    scanf("%s", x), scanf("%s", y);
    int a = Find(id[x]), b = Find(id[y]);
    if (t == 1) {
      if (opp[a] == b) {
        printf("NO\n");
        continue;
      }
      printf("YES\n");
      int s = Union(a, b);
      if (!opp[a] && !opp[b]) continue;
      int o = 0;
      if (opp[a]) o = opp[a];
      if (opp[b]) o = opp[b];
      if (opp[a] && opp[b]) o = Union(opp[a], opp[b]);
      if (o) opp[s] = o, opp[o] = s;
    } else {
      if (a == b) {
        printf("NO\n");
        continue;
      }
      printf("YES\n");
      if (opp[a]) {
        Union(opp[a], b);
        b = Find(b);
      }
      if (opp[b]) {
        Union(opp[b], a);
        a = Find(a);
      }
      opp[a] = b, opp[b] = a;
    }
  }
  for (long long i = 1, __R = q; i <= __R; i++) {
    static char x[25], y[25];
    scanf("%s", x), scanf("%s", y);
    int a = Find(id[x]), b = Find(id[y]);
    if (a == b)
      printf("1\n");
    else if (opp[a] == b)
      printf("2\n");
    else
      printf("3\n");
  }
  return 0;
}
