#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int fa[200005];
int findd(int x) {
  if (fa[x] == x)
    return x;
  else
    return fa[x] = findd(fa[x]);
}
void unit(int x, int y) {
  int fx = findd(x);
  int fy = findd(y);
  if (fx != fy) {
    fa[fx] = fy;
  }
}
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  string a;
  for (int i = 1; i <= 2 * n; i++) {
    fa[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a;
    mp[a] = i;
  }
  int re;
  char x[25];
  char y[25];
  for (int i = 0; i < m; i++) {
    scanf("%d%s%s", &re, &x, &y);
    if (re == 1) {
      if (findd(mp[x]) == findd(mp[y] + n)) {
        printf("%s\n", "NO");
        continue;
      }
      unit(mp[x], mp[y]);
      unit(mp[x] + n, mp[y] + n);
    } else {
      if (findd(mp[x]) == findd(mp[y])) {
        printf("%s\n", "NO");
        continue;
      }
      unit(mp[x], mp[y] + n);
      unit(mp[x] + n, mp[y]);
    }
    printf("%s\n", "YES");
  }
  for (int i = 0; i < q; i++) {
    scanf("%s%s", &x, &y);
    if (findd(mp[x]) == findd(mp[y])) {
      printf("%d\n", 1);
      continue;
    }
    if (findd(mp[x]) == findd(mp[y] + n)) {
      printf("%d\n", 2);
      continue;
    }
    printf("%d\n", 3);
  }
}
