#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
char s[21];
int pa[200000];
int P(int v) {
  if (v == pa[v]) return v;
  return pa[v] = P(pa[v]);
}
int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < (int)(n << 1); ++i) pa[i] = i;
  for (int i = 0; i < (int)(n); ++i) scanf("%s", s), mp[s] = i << 1;
  for (int i = 0; i < (int)(m); ++i) {
    int a, b, o;
    scanf("%d%s", &o, s);
    a = mp[s];
    scanf("%s", s);
    b = mp[s];
    o = o == 1;
    int x = P(a), y = P(b);
    if (o) {
      if ((x ^ y) == 1)
        o = false;
      else if (x != y) {
        pa[y] = x;
        pa[y ^ 1] = x ^ 1;
      }
    } else if (x != y) {
      if ((x ^ y) != 1) pa[y] = x ^ 1, pa[y ^ 1] = x;
      o = true;
    }
    printf("%s\n", o ? "YES" : "NO");
  }
  for (int i = 0; i < (int)(q); ++i) {
    int a, b;
    scanf("%s", s);
    a = mp[s];
    scanf("%s", s);
    b = mp[s];
    int x = P(a), y = P(b);
    if (x == y)
      printf("1\n");
    else if ((x ^ y) == 1)
      printf("2\n");
    else
      printf("3\n");
  }
}
