#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, m, q, col = 0;
long long color[N], root[N], sz[N];
string a[N];
map<long long, long long> c;
map<string, long long> convert;
void init() {
  for (long long i = 1; i <= n; i++) {
    root[i] = i;
    sz[i] = 1;
    root[i + n] = i + n;
    sz[i + n] = 1;
  }
}
long long rt(long long k) {
  while (k != root[k]) {
    root[k] = root[root[k]];
    k = root[k];
  }
  return k;
}
void merge(long long u, long long v) {
  long long rt1 = rt(u);
  long long rt2 = rt(v);
  if (rt1 == rt2) return;
  if (sz[rt2] >= sz[rt1]) {
    sz[rt2] += sz[rt1];
    sz[rt1] = 0;
    root[rt1] = root[rt2];
  } else {
    sz[rt1] += sz[rt2];
    sz[rt2] = 0;
    root[rt2] = root[rt1];
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(color, -1, sizeof(color));
  cin >> n >> m >> q;
  init();
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    convert[a[i]] = i;
  }
  for (long long i = 1; i <= m; i++) {
    bool check = 1;
    long long type;
    cin >> type;
    string x, y;
    cin >> x >> y;
    long long u, v;
    u = convert[x];
    v = convert[y];
    if (type == 1) {
      if (rt(u) == rt(v + n))
        check = 0;
      else {
        merge(u, v);
        merge(u + n, v + n);
      }
    } else {
      if (rt(u) == rt(v))
        check = 0;
      else {
        merge(u, v + n);
        merge(v, u + n);
      }
    }
    if (!check)
      cout << "NO"
           << "\n";
    else
      cout << "YES"
           << "\n";
  }
  for (long long i = 1; i <= q; i++) {
    string x, y;
    cin >> x >> y;
    long long u, v;
    u = convert[x];
    v = convert[y];
    if (rt(u) == rt(v))
      cout << "1"
           << "\n";
    else if (rt(u) == rt(v + n))
      cout << "2"
           << "\n";
    else
      cout << "3"
           << "\n";
  }
  return 0;
}
