#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long MAX_N = 2e5 + 10;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
map<string, int> mp;
int par[MAX_N];
int find_par(int x) { return par[x] == x ? x : (par[x] = find_par(par[x])); }
void unite(int x, int y) { par[find_par(x)] = find_par(y); }
char w[30], w1[30], w2[30];
int main() {
  int n, m, q, op, p1, p2;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", &w);
    mp[w] = i;
  }
  for (int i = 1; i <= (n * 2); ++i) par[i] = i;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%s%s", &op, &w1, &w2);
    p1 = mp[w1], p2 = mp[w2];
    if (op == 1) {
      if (find_par(p1 + n) == find_par(p2) || find_par(p1) == find_par(p2 + n))
        printf("NO\n");
      else {
        printf("YES\n");
        unite(p1, p2);
        unite(p1 + n, p2 + n);
      }
    } else {
      if (find_par(p1) == find_par(p2) || find_par(p1 + n) == find_par(p2 + n))
        printf("NO\n");
      else {
        printf("YES\n");
        unite(p1 + n, p2);
        unite(p1, p2 + n);
      }
    }
  }
  for (int i = 1; i <= q; ++i) {
    scanf("%s%s", &w1, &w2);
    p1 = mp[w1], p2 = mp[w2];
    if (find_par(p1 + n) == find_par(p2) || find_par(p1) == find_par(p2 + n))
      printf("2\n");
    else if (find_par(p1) == find_par(p2) ||
             find_par(p1 + n) == find_par(p2 + n))
      printf("1\n");
    else
      puts("3");
  }
  return 0;
}
