#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, a, b, c, d, op, maxi, mini, mij, ls, ld, ul, timp, k, maxl;
int v[1000005], multime[1000005], antonime[1000005];
string s, t;
map<string, int> idx;
int go(int first) {
  if (multime[first] == first)
    return first;
  else {
    multime[first] = go(multime[first]);
    return multime[first];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (i = 1; i <= n; i++) {
    cin >> s;
    idx[s] = i;
  }
  for (i = 1; i <= n; i++)
    multime[i] = i, multime[n + i] = n + i, antonime[i] = n + i,
    antonime[n + i] = i;
  ;
  for (i = 1; i <= m; i++) {
    int op;
    cin >> op >> s >> t;
    if (op == 1) {
      ls = idx[s], ld = idx[t];
      a = go(ls);
      b = go(ld);
      c = antonime[a];
      d = antonime[b];
      c = go(c);
      d = go(d);
      if (b != c && a != d) {
        multime[a] = b;
        multime[c] = d;
        cout << "YES\n";
      } else
        cout << "NO\n";
    } else {
      ls = idx[s], ld = idx[t];
      a = go(ls);
      b = go(ld);
      c = antonime[a];
      d = antonime[b];
      c = go(c);
      d = go(d);
      if (a != b) {
        multime[a] = d;
        multime[b] = c;
        cout << "YES\n";
      } else
        cout << "NO\n";
    }
  }
  for (i = 1; i <= k; i++) {
    cin >> s >> t;
    ls = idx[s], ld = idx[t];
    a = go(ls);
    b = go(ld);
    c = antonime[a];
    d = antonime[b];
    c = go(c);
    d = go(d);
    if (a == b)
      cout << 1;
    else if (a == d || b == c)
      cout << 2;
    else
      cout << 3;
    cout << '\n';
  }
  return 0;
}
