#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
const int M = 10000 + 10;
const int Q = 1000 + 10;
const int A = 30 + 1;
int father[N];
map<string, int> mp;
int n, m, q;
string str, s1, s2;
int op;
int x, y;
int getfather(int x) {
  return father[x] == x ? x : father[x] = getfather(father[x]);
}
int main() {
  mp.clear();
  scanf("%d%d%d", &n, &m, &q);
  for (int i(1); i <= (n); ++i) {
    cin >> str;
    mp[str] = i;
  }
  for (int i(1); i <= (n << 1); ++i) father[i] = i;
  for (int i(1); i <= (m); ++i) {
    cin >> op >> s1 >> s2;
    x = mp[s1], y = mp[s2];
    int fa = getfather(x), fb = getfather(y);
    int ga = getfather(x + n), gb = getfather(y + n);
    if (op == 1) {
      if (ga == fb)
        puts("NO");
      else {
        father[fa] = fb;
        father[ga] = gb;
        puts("YES");
      }
    } else {
      if (fa == fb)
        puts("NO");
      else {
        father[fa] = gb;
        father[ga] = fb;
        puts("YES");
      }
    }
  }
  for (int i(1); i <= (q); ++i) {
    cin >> s1 >> s2;
    x = mp[s1], y = mp[s2];
    if (getfather(x) == getfather(y))
      puts("1");
    else if (getfather(x + n) == getfather(y))
      puts("2");
    else
      puts("3");
  }
  return 0;
}
