#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
const int M = 100005;
int fa[M << 1];
int tot;
int n;
void init() {
  for (int i = 0; i < M << 1; i++) fa[i] = i;
  tot = n;
}
int find(int a) { return a == fa[a] ? a : fa[a] = find(fa[a]); }
bool unio(int a, int b) {
  int ra = find(a);
  int rb = find(b);
  if (ra < n && rb < n) {
    fa[ra] = rb;
  } else {
    if (ra > rb) swap(ra, rb);
    if (ra >= n && ra + 1 == rb && (ra - n) % 2 == 0) {
      return false;
    }
    fa[ra] = rb;
    if (ra >= n) {
      fa[n + ((ra - n) ^ 1)] = n + ((rb - n) ^ 1);
    }
  }
  return true;
}
bool refu(int a, int b) {
  int ra = find(a);
  int rb = find(b);
  if (ra == rb)
    return false;
  else {
    if (ra > rb) swap(ra, rb);
    if (ra < n && rb < n) {
      fa[ra] = tot++;
      fa[rb] = tot++;
    } else if (ra < n) {
      fa[ra] = n + ((rb - n) ^ 1);
    } else {
      if (ra + 1 == rb && (ra - n) % 2 == 0)
        ;
      else {
        fa[ra] = n + ((rb - n) ^ 1);
        fa[n + ((ra - n) ^ 1)] = rb;
      }
    }
  }
  return true;
}
int query(int a, int b) {
  int ra = find(a);
  int rb = find(b);
  if (ra == rb)
    return 1;
  else {
    if (ra > rb) swap(ra, rb);
    if (ra + 1 == rb && ra >= n && (ra - n) % 2 == 0) return 2;
    return 3;
  }
}
int main() {
  int m, q;
  string s1, s2, str;
  cin >> n >> m >> q;
  init();
  for (int i = 0; i < n; i++) {
    cin >> str;
    mp[str] = i;
  }
  int op;
  while (m--) {
    cin >> op >> s1 >> s2;
    bool t;
    if (op == 1) {
      t = unio(mp[s1], mp[s2]);
    } else {
      t = refu(mp[s1], mp[s2]);
    }
    printf("%s\n", t ? "YES" : "NO");
  }
  while (q--) {
    cin >> s1 >> s2;
    int t = query(mp[s1], mp[s2]);
    printf("%d\n", t);
  }
  return 0;
}
