#include <bits/stdc++.h>
using namespace std;
int n, m, q, pai[200200], ant[200200];
map<string, int> mapa;
int find(int x) {
  if (pai[x] == x) return x;
  return pai[x] = find(pai[x]);
}
void join(int x, int y) {
  x = find(x), y = find(y);
  ant[x] = find(ant[x]), ant[y] = find(ant[y]);
  if (x == y) {
    cout << "YES\n";
    return;
  }
  if (x == ant[y]) {
    cout << "NO\n";
    return;
  }
  pai[x] = y;
  pai[ant[x]] = ant[y];
  cout << "YES\n";
}
void disjoin(int x, int y) {
  x = find(x), y = find(y);
  ant[x] = find(ant[x]), ant[y] = find(ant[y]);
  if (x == y) {
    cout << "NO\n";
    return;
  }
  if (x == ant[y]) {
    cout << "YES\n";
    return;
  }
  pai[x] = ant[y];
  pai[ant[x]] = y;
  cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) {
    pai[i] = i;
    ant[i] = i + n, pai[ant[i]] = ant[i];
    ant[ant[i]] = i;
    string s;
    cin >> s;
    mapa[s] = i;
  }
  for (int i = 0; i < m; i++) {
    int op;
    string s1, s2;
    cin >> op >> s1 >> s2;
    if (op == 1) join(mapa[s1], mapa[s2]);
    if (op == 2) disjoin(mapa[s1], mapa[s2]);
  }
  for (int i = 0; i < q; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    int a = find(mapa[s1]), b = find(mapa[s2]);
    if (a == b)
      cout << "1\n";
    else if (a == ant[b])
      cout << "2\n";
    else
      cout << "3\n";
  }
  return 0;
}
