#include <bits/stdc++.h>
using namespace std;
int op[100500];
int p[100500];
map<string, int> s2id;
char buf[1000];
int find(int x) {
  if (p[x] == x) return x;
  return p[x] = find(p[x]);
}
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  p[b] = a;
}
bool merge(int pa, int pb) {
  if (pa == pb) {
  } else if (op[pa] == pb) {
    return false;
  } else {
    unite(pa, pb);
    if (op[pb] >= 0 && op[pa] >= 0) {
      unite(op[pa], op[pb]);
    } else if (op[pb] >= 0) {
      op[pa] = op[pb];
      op[op[pb]] = pa;
    }
  }
  return true;
}
int main() {
  int n, m, q;
  scanf("%d %d", &n, &m);
  scanf("%d", &q);
  for (int i = (0); i < (n); ++i) {
    scanf("%s", buf);
    s2id[buf] = i;
  }
  for (int i = (0); i < (n); ++i) p[i] = i;
  memset(op, -1, sizeof op);
  while (m--) {
    int a, b, t;
    scanf("%d", &t);
    scanf("%s", buf);
    a = s2id[buf];
    scanf("%s", buf);
    b = s2id[buf];
    int pa = find(a), pb = find(b);
    bool ok = true;
    if (t == 1) {
      ok = merge(pa, pb);
    } else {
      if (pa == pb) {
        ok = false;
      } else if (op[pa] == pb) {
      } else {
        if (op[pa] >= 0)
          ok = merge(op[pa], pb);
        else if (op[pb] >= 0)
          ok = merge(op[pb], pa);
        else {
          op[pa] = pb;
          op[pb] = pa;
        }
      }
    }
    puts(ok ? "YES" : "NO");
  }
  while (q--) {
    int a, b;
    scanf("%s", buf);
    a = s2id[buf];
    scanf("%s", buf);
    b = s2id[buf];
    a = find(a);
    b = find(b);
    if (a == b) {
      puts("1");
    } else if (op[a] == b) {
      puts("2");
    } else
      puts("3");
  }
}
