#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int par[MAXN * 2];
map<string, int> m;
int find(int x) { return par[x] == x ? par[x] : par[x] = find(par[x]); }
void unit(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    par[a] = b;
  }
}
bool isSame(int a, int b) {
  a = find(a);
  b = find(b);
  return a == b;
}
int main() {
  int n, r, q;
  scanf("%d%d%d", &n, &r, &q);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    m[s] = i;
  }
  for (int i = 0; i < 2 * n; ++i) par[i] = i;
  for (int i = 0; i < r; ++i) {
    int T;
    scanf("%d", &T);
    string a, b;
    cin >> a >> b;
    int A = m[a], B = m[b];
    if (T == 1) {
      if (isSame(A, B + n) || isSame(A + n, B))
        printf("NO\n");
      else {
        printf("YES\n");
        unit(A, B);
        unit(A + n, B + n);
      }
    } else {
      if (isSame(A, B) || isSame(A + n, B + n))
        printf("NO\n");
      else {
        printf("YES\n");
        unit(A, B + n);
        unit(A + n, B);
      }
    }
  }
  for (int i = 0; i < q; ++i) {
    string a, b;
    cin >> a >> b;
    int A = m[a], B = m[b];
    if (isSame(A, B) || isSame(A + n, B + n))
      printf("1\n");
    else if (isSame(A, B + n) || isSame(A + n, B))
      printf("2\n");
    else
      printf("3\n");
  }
}
