#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 123;
map<string, int> to;
int parent[N];
int rnk[N];
int opposite[N];
void make_set(int v) {
  parent[v] = v;
  rnk[v] = 0;
}
int ans[N];
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (rnk[a] < rnk[b]) swap(a, b);
    parent[b] = a;
    if (rnk[a] == rnk[b]) ++rnk[a];
  }
}
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < n; ++i) {
    opposite[i] = -1;
    string s;
    cin >> s;
    to[s] = i;
    make_set(i);
  }
  for (int i = 0; i < m; ++i) {
    int t;
    string a, b;
    cin >> t >> a >> b;
    int su = find_set(to[a]);
    int sv = find_set(to[b]);
    if (su == sv && t == 2) {
      cout << "NO\n";
      continue;
    }
    if (t == 1) {
      if (opposite[sv] != -1 && su == find_set(opposite[sv])) {
        cout << "NO\n";
        continue;
      }
      union_sets(su, sv);
      if (opposite[su] != -1 && opposite[sv] != -1) {
        union_sets(opposite[su], opposite[sv]);
      } else if (opposite[su] == -1) {
        opposite[su] = opposite[sv];
      } else {
        opposite[sv] = opposite[su];
      }
    } else {
      if (su == sv) {
        cout << "NO\n";
        continue;
      }
      if (opposite[su] != -1) {
        union_sets(opposite[su], sv);
      }
      if (opposite[sv] != -1) {
        union_sets(opposite[sv], su);
      }
      opposite[su] = sv;
      opposite[sv] = su;
    }
    cout << "YES\n";
  }
  for (int i = 0; i < q; ++i) {
    string a, b;
    cin >> a >> b;
    int u = find_set(to[a]);
    int v = find_set(to[b]);
    if (u == v) {
      cout << "1\n";
      continue;
    }
    if (opposite[v] != -1 && u == find_set(opposite[v])) {
      cout << "2\n";
      continue;
    }
    cout << 3 << "\n";
  }
  return 0;
}
