#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, n, m, res, d, q;
long long parent[200009];
long long findset(long long x) {
  if (parent[x] == x) return x;
  return parent[x] = findset(parent[x]);
}
void unionset(long long x, long long y) {
  long long xx = findset(x);
  long long yy = findset(y);
  if (xx == yy) return;
  if (rand() % 2 == 0)
    parent[xx] = yy;
  else
    parent[yy] = xx;
}
string s1, s2;
map<string, long long> mp;
int main() {
  cin >> n >> m >> q;
  for (i = 1; i <= n; i++) {
    cin >> s1;
    mp[s1] = mp.size() + 1;
  }
  for (i = 1; i <= 2 * n; i++) parent[i] = i;
  for (i = 1; i <= m; i++) {
    cin >> k >> s1 >> s2;
    if (k == 1) {
      if (findset(mp[s1]) == findset(mp[s2] + n))
        cout << "NO" << endl;
      else {
        cout << "YES" << endl;
        unionset(mp[s1], mp[s2]);
        unionset(mp[s1] + n, mp[s2] + n);
      }
    } else {
      if (findset(mp[s1]) == findset(mp[s2]))
        cout << "NO" << endl;
      else {
        cout << "YES" << endl;
        unionset(mp[s1] + n, mp[s2]);
        unionset(mp[s1], mp[s2] + n);
      }
    }
  }
  for (i = 1; i <= q; i++) {
    cin >> s1 >> s2;
    if (findset(mp[s1]) == findset(mp[s2]))
      cout << 1 << endl;
    else {
      if (findset(mp[s1] + n) == findset(mp[s2]))
        cout << 2 << endl;
      else
        cout << 3 << endl;
    }
  }
  return 0;
}
