#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> mp;
string s;
int root[100005];
int opposite[100005];
int getRoot(int x) {
  int r, i, ax;
  for (r = x; root[r] != r; r = root[r])
    ;
  for (i = x; root[i] != i; i = root[i]) {
    ax = root[i];
    root[i] = r;
    i = ax;
  }
  return r;
}
int getRelation(int x, int y) {
  int r1, r2, i, ax;
  for (r1 = x; root[r1] != r1; r1 = root[r1])
    ;
  for (i = x; root[i] != i;) {
    ax = root[i];
    root[i] = r1;
    i = ax;
  }
  for (r2 = y; root[r2] != r2; r2 = root[r2])
    ;
  for (i = y; root[i] != i;) {
    ax = root[i];
    root[i] = r2;
    i = ax;
  }
  if (r1 == r2 && (getRoot(opposite[r1]) == getRoot(opposite[r2]) ||
                   getRoot(opposite[r1]) == 0 || getRoot(opposite[r2]) == 0)) {
    return 1;
  } else if (getRoot(opposite[r1]) == r2 && getRoot(opposite[r2]) == r1) {
    return 2;
  }
  return 3;
}
void merge_v(int x, int y) {
  if (x == 0 || y == 0 || x == y) {
    return;
  }
  int r1, r2, i, ax;
  for (r1 = x; root[r1] != r1; r1 = root[r1])
    ;
  for (r2 = y; root[r2] != r2; r2 = root[r2])
    ;
  root[r1] = r2;
  if (getRoot(opposite[r2]) == 0) {
    opposite[r2] = opposite[r1];
  }
  if (getRelation(opposite[r1], opposite[r2]) == 3) {
    merge_v(opposite[r1], opposite[r2]);
  }
  for (i = y; root[i] != i;) {
    ax = root[i];
    root[i] = r2;
    i = ax;
  }
  for (i = x; root[i] != i;) {
    ax = root[i];
    root[i] = r2;
    i = ax;
  }
}
void op_v(int x, int y) {
  if (x == 0 || y == 0 || x == y) {
    return;
  }
  int r1, r2, i, ax;
  for (r1 = x; root[r1] != r1; r1 = root[r1])
    ;
  for (r2 = y; root[r2] != r2; r2 = root[r2])
    ;
  for (i = y; root[i] != i;) {
    ax = root[i];
    root[i] = r2;
    i = ax;
  }
  for (i = x; root[i] != i;) {
    ax = root[i];
    root[i] = r1;
    i = ax;
  }
  if (getRoot(opposite[r1]) != r2 && getRoot(opposite[r1])) {
    if (getRelation(opposite[r1], r2) == 3) {
      merge_v(r2, opposite[r1]);
    }
  } else if (getRoot(opposite[r1]) == 0) {
    opposite[r1] = r2;
  }
  if (getRoot(opposite[r2]) != r1 && getRoot(opposite[r2])) {
    if (getRelation(opposite[r2], r1) == 3) {
      merge_v(r1, opposite[r2]);
    }
  } else if (getRoot(opposite[r2]) == 0) {
    opposite[r2] = r1;
  }
}
int main() {
  int i, n, m, q, x, y, op;
  scanf("%d %d %d", &n, &m, &q);
  for (i = 1; i <= n; i++) {
    cin >> s;
    mp[s] = i;
    root[i] = i;
  }
  for (i = 1; i <= m; i++) {
    cin >> op;
    cin >> s;
    x = mp[s];
    cin >> s;
    y = mp[s];
    int t = getRelation(x, y);
    if (t == op) {
      cout << "YES";
    } else if (t == 3) {
      if (op == 1) {
        merge_v(x, y);
      } else {
        op_v(x, y);
      }
      cout << "YES";
    } else {
      cout << "NO";
    }
    cout << "\n";
  }
  for (i = 1; i <= q; i++) {
    cin >> s;
    x = mp[s];
    cin >> s;
    y = mp[s];
    cout << getRelation(x, y) << '\n';
  }
  return 0;
}
