#include <bits/stdc++.h>
using namespace std;
int n, m, q, i, j, p[200005];
string s, s1;
map<string, int> id;
int find(int s) {
  if (p[s] == s) return s;
  return p[s] = find(p[s]);
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (i = 0; i < n + n; i++) p[i] = i;
  for (i = 0; i < n; i++) {
    cin >> s;
    id[s] = i;
  }
  for (i = 0; i < m; i++) {
    int t, x, y;
    scanf("%d", &t);
    cin >> s >> s1;
    x = id[s];
    y = id[s1];
    if (t == 1) {
      if (find(x) == find(y + n) || find(y) == find(x + n)) {
        printf("NO\n");
        continue;
      }
      int u = find(x);
      int v = find(y);
      p[u] = v;
      u = find(x + n);
      v = find(y + n);
      p[u] = v;
      printf("YES\n");
    } else {
      if (find(x) == find(y) || find(x + n) == find(y + n)) {
        printf("NO\n");
        continue;
      }
      int u = find(x);
      int v = find(y + n);
      p[u] = v;
      u = find(x + n);
      v = find(y);
      p[u] = v;
      printf("YES\n");
    }
  }
  for (i = 0; i < q; i++) {
    cin >> s >> s1;
    int x = id[s];
    int y = id[s1];
    if (find(x) == find(y) || find(x + n) == find(y + n))
      printf("1\n");
    else if (find(x) == find(y + n) || find(x + n) == find(y))
      printf("2\n");
    else
      printf("3\n");
  }
}
