#include <bits/stdc++.h>
struct query {
  int word;
  char s[32];
  int id, type, i;
} qq[100000 * 3 + 100000 * 2];
int qcompare(const void *a, const void *b) {
  struct query *pa = (struct query *)a;
  struct query *pb = (struct query *)b;
  return !pa->word && !pb->word ? 0
                                : (pa->word != pb->word ? pb->word - pa->word
                                                        : strcmp(pa->s, pb->s));
}
int icompare(const void *a, const void *b) {
  struct query *pa = (struct query *)a;
  struct query *pb = (struct query *)b;
  return pa->i - pb->i;
}
int scompare(const void *a, const void *b) {
  char **pa = (char **)a;
  char **pb = (char **)b;
  return strcmp(*pa, *pb);
}
struct W {
  int dsu, diff;
} ww[100000];
int find(int u) {
  int p, root;
  if ((p = ww[u].dsu) < 0) {
    ww[u].diff = 0;
    return u;
  }
  root = (ww[u].dsu = find(ww[u].dsu));
  ww[u].diff ^= ww[p].diff;
  return root;
}
void join(int u, int v, int same) {
  int diff = ww[u].diff == ww[v].diff ? (same ? 0 : 1) : (same ? 1 : 0);
  u = find(u);
  v = find(v);
  if (u == v) return;
  if (ww[u].dsu < ww[v].dsu) {
    ww[v].dsu = u;
    ww[v].diff = diff;
  } else if (ww[u].dsu > ww[v].dsu) {
    ww[u].dsu = v;
    ww[u].diff = diff;
  } else {
    ww[u].dsu--;
    ww[v].dsu = u;
    ww[v].diff = diff;
  }
}
int same(int u, int v) { return ww[u].diff == ww[v].diff; }
int main() {
  static char s[32], t[32], *ss[100000];
  int n, m, q, i, j;
  scanf("%d%d%d", &n, &m, &q);
  for (i = 0; i < n; i++) {
    scanf("%s", s);
    ss[i] = strdup(s);
  }
  qsort(ss, n, sizeof *ss, scompare);
  for (i = 0; i < m * 3 + q * 2; i++) qq[i].i = i;
  for (i = 0; i < m; i++) {
    int type;
    scanf("%d", &type);
    scanf("%s", s);
    scanf("%s", t);
    qq[i * 3].word = 0;
    qq[i * 3].type = type;
    qq[i * 3 + 1].word = 1;
    memcpy(qq[i * 3 + 1].s, s, strlen(s));
    qq[i * 3 + 2].word = 1;
    memcpy(qq[i * 3 + 2].s, t, strlen(t));
  }
  for (i = 0; i < q; i++) {
    scanf("%s", s);
    scanf("%s", t);
    qq[m * 3 + i * 2].word = 1;
    memcpy(qq[m * 3 + i * 2].s, s, strlen(s));
    qq[m * 3 + i * 2 + 1].word = 1;
    memcpy(qq[m * 3 + i * 2 + 1].s, t, strlen(t));
  }
  qsort(qq, m * 3 + q * 2, sizeof *qq, qcompare);
  j = 0;
  for (i = 0; i < m * 2 + q * 2; i++) {
    while (j < n && strcmp(qq[i].s, ss[j]) != 0) j++;
    qq[i].id = j;
  }
  qsort(qq, m * 3 + q * 2, sizeof *qq, icompare);
  for (i = 0; i < n; i++) ww[i].dsu = -1, ww[i].diff = 0;
  for (i = 0; i < m; i++) {
    struct query q1 = qq[i * 3];
    struct query q2 = qq[i * 3 + 1];
    struct query q3 = qq[i * 3 + 2];
    int u = q2.id;
    int v = q3.id;
    if (q1.type == 1) {
      if (find(u) != find(v) || same(u, v)) {
        join(u, v, 1);
        printf("YES\n");
      } else
        printf("NO\n");
    } else {
      if (find(u) != find(v) || !same(u, v)) {
        join(u, v, 0);
        printf("YES\n");
      } else
        printf("NO\n");
    }
  }
  for (i = 0; i < q; i++) {
    struct query q1 = qq[m * 3 + i * 2];
    struct query q2 = qq[m * 3 + i * 2 + 1];
    int u = q1.id;
    int v = q2.id;
    printf("%d\n", find(u) != find(v) ? 3 : (ww[u].diff == ww[v].diff ? 1 : 2));
  }
  return 0;
}
