#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m, q, k = 1;
map<string, int> idx;
int p[N], opposite[N];
int f(int x) {
  if (x != p[x]) {
    return p[x] = f(p[x]);
  }
  return x;
}
void un(int x, int y) {
  x = f(x);
  y = f(y);
  p[x] = y;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    idx[s] = k++;
  }
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    p[n + i] = n + i;
    opposite[i] = n + i;
    p[n + i] = n + i;
  }
  for (int i = 0; i < m; i++) {
    int t;
    string a, b;
    cin >> t >> a >> b;
    int x = idx[a], y = idx[b];
    x = f(x);
    y = f(y);
    opposite[x] = f(opposite[x]);
    opposite[y] = f(opposite[y]);
    opposite[opposite[x]] = x;
    opposite[opposite[y]] = y;
    if (t == 1) {
      if (x == opposite[y]) {
        cout << "NO\n";
      } else {
        cout << "YES\n";
        un(x, y);
        un(opposite[x], opposite[y]);
      }
    } else {
      if (x == y) {
        cout << "NO\n";
      } else {
        cout << "YES\n";
        un(x, opposite[y]);
        un(opposite[x], y);
      }
    }
  }
  for (int i = 0; i < q; i++) {
    string s, t;
    cin >> s >> t;
    int x = f(idx[s]), y = f(idx[t]);
    if (x == y) {
      cout << "1\n";
    } else if (x == opposite[y]) {
      cout << ("2\n");
    } else {
      cout << ("3\n");
    }
  }
  return 0;
}
