#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 60);
const int MX = 300009;
int n, m, q, same[MX], opp[MX], osz[MX], ssz[MX], par[MX], non[MX * 3];
map<string, int> idx;
int head(int x) {
  if (par[x] == x) return x;
  return par[x] = head(par[x]);
}
int Same(int a, int b) { return head(a) == head(b); }
int Opp(int a, int b) { return head(non[a]) == head(b); }
void merge_same(int a, int b) {
  a = head(a);
  b = head(b);
  par[head(non[a])] = head(non[b]);
  par[a] = b;
}
void merge_opp(int a, int b) { merge_same(head(a), head(non[head(b)])); }
string s;
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    idx[s] = i;
    non[i] = i + MX;
    non[i + MX] = i;
    par[i] = i;
    par[i + MX] = i + MX;
  }
  while (m--) {
    string s, s1;
    int x;
    cin >> x >> s >> s1;
    int a, b;
    a = idx[s];
    b = idx[s1];
    if (x == 1) {
      if (Opp(a, b)) {
        puts("NO");
        continue;
      }
      puts("YES");
      merge_same(a, b);
    }
    if (x == 2) {
      if (Same(a, b)) {
        puts("NO");
        continue;
      }
      puts("YES");
      merge_opp(a, b);
    }
  }
  while (q--) {
    string s, s1;
    cin >> s >> s1;
    int a = idx[s], b = idx[s1];
    if (Same(a, b))
      puts("1");
    else if (Opp(a, b))
      puts("2");
    else
      puts("3");
  }
}
