#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
int pa[MAXN];
map<string, int> sign;
int findset(int x) { return pa[x] != x ? pa[x] = findset(pa[x]) : x; }
void uni(int s, int e) {
  int pas = findset(s), pae = findset(e);
  if (pas != pae) pa[pas] = pae;
}
int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= 2 * n; i++) pa[i] = i;
  for (int i = 1; i <= n; i++) {
    string ch;
    cin >> ch;
    sign[ch] = i;
  }
  string s, e, pas, pae;
  for (int i = 0; i < m; i++) {
    int t;
    int ans = 0;
    scanf("%d", &t);
    cin >> s >> e;
    int id1 = sign[s], id2 = sign[e];
    if (t == 1) {
      if (findset(2 * id1) == findset(2 * id2 - 1))
        cout << "NO" << endl;
      else if (findset(2 * id2) == findset(2 * id1 - 1))
        cout << "NO" << endl;
      else {
        cout << "YES" << endl;
        uni(2 * id1, 2 * id2);
        uni(2 * id1 - 1, 2 * id2 - 1);
      }
    } else {
      if (findset(2 * id1) == findset(2 * id2))
        cout << "NO" << endl;
      else if (findset(2 * id1 - 1) == findset(2 * id2 - 1))
        cout << "NO" << endl;
      else {
        cout << "YES" << endl;
        uni(2 * id1, 2 * id2 - 1);
        uni(2 * id1 - 1, 2 * id2);
      }
    }
  }
  for (int i = 0; i < q; i++) {
    cin >> s >> e;
    int id1 = sign[s], id2 = sign[e];
    if (findset(2 * id1) == findset(2 * id2))
      cout << 1 << endl;
    else if (findset(2 * id1 - 1) == findset(2 * id2 - 1))
      cout << 1 << endl;
    else if (findset(2 * id1) == findset(2 * id2 - 1))
      cout << 2 << endl;
    else if (findset(2 * id2) == findset(2 * id1))
      cout << 2 << endl;
    else
      cout << 3 << endl;
  }
  return 0;
}
