#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> mp;
vector<int> p;
vector<int> sz;
vector<int> opp;
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
void join(int x, int y) {
  int i = find(x), j = find(y);
  if (i == j) return;
  if (sz[i] > sz[j]) swap(i, j);
  sz[i] += sz[j];
  p[j] = i;
}
int main() {
  ios::sync_with_stdio(0);
  int n, m, q, i, u, v, pu, pv, t;
  string s;
  cin >> n >> m >> q;
  p.resize(n + 1);
  iota(p.begin(), p.end(), 0);
  sz.assign(n + 1, 1);
  opp.assign(n + 1, -1);
  for (i = 1; i <= n; ++i) {
    cin >> s;
    mp[s] = i;
  }
  for (i = 1; i <= m; ++i) {
    cin >> t;
    cin >> s;
    u = mp[s];
    cin >> s;
    v = mp[s];
    pu = find(u), pv = find(v);
    if (t == 1) {
      if (opp[pu] != -1 && pv == find(opp[pu])) {
        cout << "NO\n";
      } else {
        cout << "YES\n";
        if (opp[pu] == -1 && opp[pv] != -1)
          opp[pu] = opp[pv];
        else if (opp[pu] != -1 && opp[pv] == -1)
          opp[pv] = opp[pu];
        else if (opp[pu] != -1 && opp[pv] != -1)
          join(opp[pu], opp[pv]);
        join(pu, pv);
        opp[find(pu)] = opp[pu];
      }
    } else if (t == 2) {
      if (pu == pv) {
        cout << "NO\n";
      } else {
        cout << "YES\n";
        if (opp[pu] != -1) join(opp[pu], pv);
        if (opp[pv] != -1) join(opp[pv], pu);
        opp[pu] = find(pv);
        opp[pv] = find(pu);
      }
    }
  }
  for (i = 1; i <= q; ++i) {
    cin >> s;
    u = mp[s];
    cin >> s;
    v = mp[s];
    pu = find(u), pv = find(v);
    if (pu == pv)
      cout << "1\n";
    else if (opp[pu] != -1 && pv == find(opp[pu]))
      cout << "2\n";
    else
      cout << "3\n";
  }
  return 0;
}
