#include <bits/stdc++.h>
using namespace std;
int f[100010], a[100010];
string s;
int n, m, q;
map<string, int> name;
int sf(int x) {
  if (f[x] == x) return x;
  int k = f[x];
  f[x] = sf(f[x]);
  a[x] = (a[x] + a[k]) % 2;
  return f[x];
}
int main() {
  int i, j, k, l, fa, fb, aa, bb;
  cin >> n >> m >> q;
  s.resize(25);
  for (i = 1; i <= n; i++) {
    s = "";
    s.resize(25);
    scanf("%s", &s[0]);
    name[s] = i;
  }
  for (i = 1; i <= n; i++) {
    f[i] = i;
    a[i] = 0;
  }
  for (i = 1; i <= m; i++) {
    scanf("%d", &k);
    k--;
    s = "";
    s.resize(25);
    scanf("%s", &s[0]);
    aa = name[s];
    s = "";
    s.resize(25);
    scanf("%s", &s[0]);
    bb = name[s];
    fa = sf(aa);
    fb = sf(bb);
    if (fa != fb) {
      f[fb] = fa;
      a[fb] = (k + a[aa] + a[bb]) % 2;
      printf("YES\n");
    } else {
      l = (a[aa] + a[bb]) % 2;
      if (l != k)
        printf("NO\n");
      else
        printf("YES\n");
    }
  }
  for (i = 1; i <= q; i++) {
    s = "";
    s.resize(25);
    scanf("%s", &s[0]);
    aa = name[s];
    s = "";
    s.resize(25);
    scanf("%s", &s[0]);
    bb = name[s];
    fa = sf(aa);
    fb = sf(bb);
    if (fa != fb)
      printf("3\n");
    else {
      l = (a[aa] + a[bb]) % 2;
      printf("%d\n", l + 1);
    }
  }
  return 0;
}
