#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int SZ = 2e5 + 1;
int p[SZ], d[SZ], r[SZ];
int get(int v) {
  if (v != p[v]) p[v] = get(p[v]);
  return p[v];
}
void join(int u, int v) {
  v = get(v);
  u = get(u);
  if (r[v] < r[u]) swap(v, u);
  p[u] = v;
  if (r[u] = r[v]) r[v]++;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, q, tv;
  cin >> n >> m >> q;
  unordered_map<string, int> dt;
  string s, t;
  for (int i = 0; i < n; i++) {
    cin >> s;
    dt[s] = i;
  }
  for (int i = 0; i < n; i++) {
    p[i] = i;
    d[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    cin >> tv >> s >> t;
    int v = dt[s], u = dt[t];
    if (tv == 1) {
      if (get(v) == d[get(u)]) {
        cout << "NO\n";
        continue;
      }
      cout << "YES\n";
      if (get(v) == get(u)) continue;
      if (d[get(v)] == -1) swap(u, v);
      if (d[get(u)] == -1 && d[get(v)] == -1)
        join(u, v);
      else if (d[get(u)] == -1) {
        d[get(u)] = d[get(v)];
        join(u, v);
        d[d[get(u)]] = get(u);
      } else {
        join(d[get(u)], d[get(v)]);
        d[get(u)] = get(d[get(u)]);
        d[get(v)] = get(d[get(v)]);
        join(u, v);
        d[d[get(u)]] = get(u);
      }
    } else {
      if (get(v) == get(u)) {
        cout << "NO\n";
        continue;
      }
      cout << "YES\n";
      if (d[get(v)] == get(u)) continue;
      if (d[get(v)] == -1) swap(u, v);
      if (d[get(u)] == -1 && d[get(v)] != -1)
        join(get(u), d[get(v)]);
      else if (d[get(u)] != -1 && d[get(v)] != -1) {
        int pu = d[get(u)], pv = d[get(v)];
        join(v, pu);
        join(u, pv);
      }
      d[get(v)] = get(u);
      d[get(u)] = get(v);
    }
  }
  for (int i = 0; i < q; i++) {
    cin >> s >> t;
    int v = dt[s], u = dt[t];
    if (get(v) == get(u))
      cout << "1\n";
    else if (d[get(v)] == get(u))
      cout << "2\n";
    else
      cout << "3\n";
  }
  return 0;
}
