#include <bits/stdc++.h>
using namespace std;
const int N = 201110;
int lab[N], val[N];
vector<int> gr[N];
map<string, int> mp;
int n, m, q;
int root(int u) {
  if (lab[u] < 0)
    return u;
  else
    return lab[u] = root(lab[u]);
}
void join(int type, int u, int v) {
  if (lab[u] < lab[v]) {
    lab[u] += lab[v];
    lab[v] = u;
    for (int i = 0; i < gr[v].size(); i++) {
      gr[u].push_back(gr[v][i]);
      val[gr[v][i]] *= type;
    }
    gr[v].clear();
  } else {
    lab[v] += lab[u];
    lab[u] = v;
    for (int i = 0; i < gr[u].size(); i++) {
      gr[v].push_back(gr[u][i]);
      val[gr[u][i]] *= type;
    }
    gr[u].clear();
  }
}
string read() {
  char ch;
  string ans = "";
  while (ch = getchar()) {
    if ('a' <= ch && ch <= 'z') break;
  }
  ans = ans + ch;
  while (ch = getchar()) {
    if (ch < 'a' || ch > 'z') break;
    ans = ans + ch;
  }
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  int k = 0;
  string st;
  int type, u, v;
  for (int i = 1; i <= n; i++) {
    val[i] = 1;
    gr[i].push_back(i);
    st = read();
    mp[st] = i;
  }
  memset(lab, 255, sizeof(lab));
  for (int i = 1; i <= m; i++) {
    scanf("%d", &type);
    st = read();
    u = mp[st];
    st = read();
    v = mp[st];
    if (root(u) != root(v)) {
      if ((val[u] == val[v] && type == 1) || (val[u] != val[v] && type == 2))
        join(1, root(u), root(v));
      else
        join(-1, root(u), root(v));
      puts("YES");
    } else {
      if ((val[u] != val[v] && type == 1) || (val[u] == val[v] && type == 2))
        puts("NO");
      else
        puts("YES");
    }
  }
  for (int i = 1; i <= q; i++) {
    st = read();
    u = mp[st];
    st = read();
    v = mp[st];
    if (root(u) != root(v))
      printf("3\n");
    else {
      if (val[u] == val[v])
        printf("1\n");
      else
        printf("2\n");
    }
  }
}
