#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
map<string, int> ma;
int parent[maxn * 2];
int find(int p) {
  if (p == parent[p]) return p;
  return parent[p] = find(parent[p]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 1; i <= 2 * n; i++) parent[i] = i;
  for (int i = 1; i <= n; i++) {
    string a;
    cin >> a;
    ma[a] = i;
  }
  for (int i = 1; i <= m; i++) {
    int op;
    string a, b;
    cin >> op >> a >> b;
    int x1 = find(ma[a]), x2 = find(ma[a] + n);
    int y1 = find(ma[b]), y2 = find(ma[b] + n);
    if (op == 1) {
      if (x1 == y2) {
        cout << "NO" << '\n';
        continue;
      }
      cout << "YES" << '\n';
      parent[x1] = y1;
      parent[x2] = y2;
    } else {
      if (x1 == y1) {
        cout << "NO" << '\n';
        continue;
      }
      cout << "YES" << '\n';
      parent[x1] = y2;
      parent[x2] = y1;
    }
  }
  while (q--) {
    string a, b;
    cin >> a >> b;
    int x1 = find(ma[a]), x2 = find(ma[a] + n);
    int y1 = find(ma[b]), y2 = find(ma[b] + n);
    if (x1 == y1)
      cout << 1 << '\n';
    else if (x1 == y2)
      cout << 2 << '\n';
    else
      cout << 3 << '\n';
  }
  return 0;
}
