#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = 0x3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
map<string, int> mapa;
int id[212345], sz[212345];
int n, m, Q;
int find(int a) {
  if (id[a] == a) return a;
  return find(id[a]);
}
void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return;
  if (sz[a] < sz[b]) swap(a, b);
  sz[a] += sz[b];
  id[b] = a;
}
bool merge_amigo(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return true;
  int ia, ib;
  ia = find(a + n);
  ib = find(b + n);
  if (ia == b || ib == a) return false;
  merge(ia, ib);
  merge(a, b);
  return true;
}
bool merge_inimigo(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return false;
  int ia, ib;
  ia = find(a + n);
  ib = find(b + n);
  if (ia == ib) return false;
  if (ia == b || ib == a) return true;
  merge(ia, b);
  merge(ib, a);
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> Q;
  string s, q;
  for (int i = 1; i <= n; i++) {
    id[i] = i;
    sz[i] = 1;
    id[n + i] = n + i;
    sz[n + i] = 0;
    cin >> s;
    mapa[s] = i;
  }
  int op;
  for (int i = 0; i < m; i++) {
    cin >> op >> s >> q;
    int a, b;
    a = mapa[s];
    b = mapa[q];
    if (op == 1) {
      if (merge_amigo(a, b))
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    } else {
      if (merge_inimigo(a, b))
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  int a, b;
  for (int i = 0; i < Q; i++) {
    cin >> s >> q;
    a = mapa[s];
    b = mapa[q];
    a = find(a);
    b = find(b);
    if (b == a)
      cout << 1 << endl;
    else if (find(a + n) == b || find(b + n) == a)
      cout << 2 << endl;
    else
      cout << 3 << endl;
  }
}
