#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int N = 1e5 + 10;
int n, m, q, t, fa[N << 1], a, b;
string s1, s2;
map<string, int> M;
int Find(int c) {
  int p = c, i = c, j;
  while (fa[p] != p) p = fa[p];
  while (fa[i] != p) j = fa[i], fa[i] = p, i = j;
  return p;
}
void Unite(int u, int v) {
  int fau = Find(u), fav = Find(v);
  if (fau != fav) fa[fav] = fau;
}
int main() {
  cin >> n >> m >> q;
  for (int i = 1; i <= n << 1; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) cin >> s1, M[s1] = i;
  for (int i = 1; i <= m; i++) {
    cin >> t >> s1 >> s2;
    a = M[s1], b = M[s2];
    if (t == 1) {
      if (Find(2 * a) == Find(2 * b - 1))
        puts("NO");
      else {
        Unite(2 * a, 2 * b);
        Unite(2 * a - 1, 2 * b - 1);
        puts("YES");
      }
    } else {
      if (Find(2 * a) == Find(2 * b))
        puts("NO");
      else {
        Unite(2 * a, 2 * b - 1);
        Unite(2 * a - 1, 2 * b);
        puts("YES");
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    cin >> s1 >> s2;
    a = M[s1], b = M[s2];
    if (Find(2 * a) == Find(2 * b))
      puts("1");
    else if (Find(2 * a) == Find(2 * b - 1))
      puts("2");
    else
      puts("3");
  }
  return 0;
}
