#include <bits/stdc++.h>
using namespace std;
const int N = (long long)(1e5) + 2;
struct dsu {
  int p[(int)(1e6) + 100], rnk[(int)(1e6) + 100];
  dsu() {
    memset(rnk, 0, sizeof(rnk));
    for (int i = 0; i < (int)(1e6) + 100; i++) p[i] = i;
  }
  int findParent(int x) {
    if (x == p[x]) return x;
    return p[x] = findParent(p[x]);
  }
  bool Connected(int x, int y) { return (findParent(x) == findParent(y)); }
  void connect(int x, int y) {
    x = findParent(x);
    y = findParent(y);
    if (!Connected(x, y)) {
      if (rnk[x] == rnk[y]) {
        rnk[x]++;
        p[y] = x;
      }
      rnk[y] > rnk[x] ? p[x] = y : p[y] = x;
    }
  }
};
int main() {
  int n, m, q, t;
  string a, b;
  dsu d;
  cin >> n >> m >> q;
  map<string, int> idx;
  for (int i = 1; i <= n; i++) cin >> a, idx[a] = i;
  while (m--) {
    cin >> t >> a >> b;
    int idxA = idx[a], idxB = idx[b];
    if (t == 1) {
      if (d.Connected(N + idxA, idxB))
        cout << "NO" << endl;
      else {
        d.connect(idxA, idxB);
        d.connect(N + idxA, N + idxB);
        cout << "YES" << endl;
      }
    } else {
      if (d.Connected(idxA, idxB))
        cout << "NO" << endl;
      else {
        d.connect(N + idxA, idxB);
        d.connect(idxA, N + idxB);
        cout << "YES" << endl;
      }
    }
  }
  while (q--) {
    cin >> a >> b;
    int idxA = idx[a], idxB = idx[b];
    if (d.Connected(idxA, idxB))
      cout << 1 << endl;
    else if (d.Connected(N + idxA, idxB))
      cout << 2 << endl;
    else
      cout << 3 << endl;
  }
  return 0;
}
