#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> mp;
vector<int> pset;
vector<int> ant;
void init(int n) {
  pset.resize(n);
  ant.resize(n);
  iota(pset.begin(), pset.end(), 0);
  fill(ant.begin(), ant.end(), -1);
}
int findSet(int a) { return pset[a] == a ? a : (pset[a] = findSet(pset[a])); }
bool isSameSet(int a, int b) { return findSet(a) == findSet(b); }
void unionSet(int a, int b) {
  if (isSameSet(a, b)) return;
  if (findSet(a) < findSet(b))
    pset[findSet(b)] = findSet(a);
  else
    pset[findSet(a)] = findSet(b);
}
bool op1(int a, int b) {
  int pa = findSet(a), pb = findSet(b);
  if (ant[pa] == pb) return false;
  int temp = -1;
  if (ant[pa] != -1 && ant[pb] != -1) unionSet(ant[pa], ant[pb]);
  if (ant[pa] != -1 || ant[pb] != -1) temp = max(ant[pa], ant[pb]);
  unionSet(a, b);
  if (temp != -1) {
    ant[findSet(temp)] = findSet(a);
    ant[findSet(a)] = findSet(temp);
  }
  return true;
}
bool op2(int a, int b) {
  int pa = findSet(a), pb = findSet(b);
  if (pa == pb) return false;
  int temp = -1;
  if (ant[pa] != -1) unionSet(pb, ant[pa]);
  if (ant[pb] != -1) unionSet(pa, ant[pb]);
  pa = findSet(a), pb = findSet(b);
  ant[pa] = pb;
  ant[pb] = pa;
  return true;
}
int main() {
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    mp[s] = i;
  }
  init(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    string s;
    cin >> a;
    cin >> s;
    b = mp[s];
    cin >> s;
    c = mp[s];
    if (a == 1) {
      if (op1(b, c))
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
      continue;
    }
    if (op2(b, c))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  for (int i = 0; i < q; i++) {
    string s;
    int a, b;
    cin >> s;
    a = mp[s];
    cin >> s;
    b = mp[s];
    if (isSameSet(a, b))
      cout << "1" << endl;
    else if (ant[findSet(a)] == findSet(b))
      cout << "2" << endl;
    else
      cout << "3" << endl;
  }
  return 0;
}
