#include <bits/stdc++.h>
using namespace std;
using namespace std;
const double pi = acos(-1.0);
const int maxn = 1e5 + 1;
map<string, long long> ma;
inline long long id(const string &str) { return ma[str]; }
int pa[maxn], d[maxn] = {0};
int findpa(int id) {
  if (id == pa[id]) return id;
  int f = pa[id];
  pa[id] = findpa(pa[id]);
  d[id] = (d[id] + d[f]) % 2;
  return pa[id];
}
bool merge(int x, int y, int v) {
  findpa(x);
  findpa(y);
  if (pa[x] != pa[y]) {
    d[pa[x]] = ((v + d[y] - d[x]) % 2 + 2) % 2;
    pa[pa[x]] = pa[y];
    return true;
  } else {
    bool ret = d[x] % 2 != d[y] % 2;
    return ret == v;
  }
}
int n, m, q;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> q;
  for (long long(i) = (0); (i) < (maxn); ++(i)) pa[i] = i;
  memset(d, 0, sizeof(d));
  for (long long(i) = (0); (i) < (n); ++(i)) {
    string str;
    cin >> str;
    ma[str] = i;
  }
  int v;
  string a, b;
  for (long long(i) = (0); (i) < (m); ++(i)) {
    cin >> v >> a >> b;
    v -= 1;
    if (merge(id(a), id(b), v))
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  for (long long(i) = (0); (i) < (q); ++(i)) {
    cin >> a >> b;
    int x = id(a), y = id(b);
    int dis;
    findpa(x);
    findpa(y);
    if (pa[x] != pa[y])
      cout << 3 << '\n';
    else if (d[x] % 2 == d[y] % 2)
      cout << 1 << '\n';
    else
      cout << 2 << '\n';
  }
}
