#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, inf = 1e9 + 10, MOD = 1e9 + 7, Sq = 708;
const long long INF = 1e18 + 10;
unordered_map<string, int> mp;
unordered_set<int> comp[maxn];
int par[maxn], en[maxn];
inline void disjoin(int u, int v);
inline void join(int u, int v) {
  u = par[u];
  v = par[v];
  if (u == v) return;
  if (comp[u].size() > comp[v].size()) swap(u, v);
  while (comp[u].size()) {
    int t = *comp[u].begin();
    par[t] = v;
    comp[v].insert(t);
    comp[u].erase(comp[u].begin());
  }
  if (en[u] != -1) disjoin(en[u], v);
}
inline void disjoin(int u, int v) {
  u = par[u];
  v = par[v];
  if (en[v] != -1) join(en[v], u);
  if (en[u] != -1) join(en[u], v);
  u = par[u];
  v = par[v];
  en[u] = v;
  en[v] = u;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, k, x, y;
  string s, p;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> s;
    mp[s] = i;
    par[i] = i;
    comp[i].insert(i);
    en[i] = -1;
  }
  for (int i = 0, t; i < m; i++) {
    cin >> t >> s >> p;
    x = mp[s];
    y = mp[p];
    if (t == 1) {
      if (par[x] == par[y]) {
        cout << "YES" << endl;
        continue;
      }
      if (en[par[x]] == par[y]) {
        cout << "NO" << endl;
        continue;
      }
      join(x, y);
      cout << "YES" << endl;
    } else {
      if (par[x] == par[y]) {
        cout << "NO" << endl;
        continue;
      }
      if (en[par[x]] == par[y]) {
        cout << "YES" << endl;
        continue;
      }
      disjoin(x, y);
      cout << "YES" << endl;
    }
  }
  for (int i = 0; i < k; i++) {
    cin >> s >> p;
    x = mp[s];
    y = mp[p];
    if (par[x] == par[y]) {
      cout << 1 << endl;
      continue;
    }
    if (en[par[x]] == par[y])
      cout << 2 << endl;
    else
      cout << 3 << endl;
  }
  return 0;
}
