#include <bits/stdc++.h>
using namespace std;
int tata[200010];
int opus[200010];
int g[200010];
int find(int a);
void unite(int a, int b);
map<string, int> ind;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, q;
  cin >> n >> m >> q;
  string s;
  for (int i(1); i <= n; i++) {
    cin >> s;
    ind[s] = i;
    tata[i] = i, g[i] = 1;
  }
  while (m--) {
    int t;
    string a, b;
    cin >> t >> a >> b;
    int x(find(ind[a])), y(find(ind[b]));
    if (t == 1) {
      if (find(opus[x]) == find(y)) {
        cout << "NO\n";
        continue;
      }
      unite(x, y);
      cout << "YES\n";
    } else {
      if (find(x) == find(y)) {
        cout << "NO\n";
        continue;
      }
      cout << "YES\n";
      if (find(opus[x]) == find(y)) continue;
      if (opus[x] != 0)
        unite(opus[x], y);
      else
        opus[x] = y;
      if (opus[y] != 0)
        unite(opus[y], x);
      else
        opus[y] = x;
    }
  }
  while (q--) {
    string a, b;
    cin >> a >> b;
    int x(ind[a]), y(ind[b]);
    x = find(x), y = find(y);
    if (find(x) == find(y))
      cout << "1\n";
    else if (find(x) == find(opus[y]))
      cout << "2\n";
    else
      cout << "3\n";
  }
  return 0;
}
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return;
  if (g[a] > g[b]) {
    g[a] += g[b];
    tata[b] = a;
  } else {
    g[b] += g[a];
    tata[a] = b;
  }
  if (opus[a] != 0 && opus[b] != 0 && find(opus[a]) != find(opus[b]))
    unite(opus[a], opus[b]);
  if (opus[a]) opus[b] = opus[a];
  if (opus[b]) opus[a] = opus[b];
}
int find(int a) {
  if (tata[tata[a]] == tata[a]) return tata[a];
  tata[a] = find(tata[a]);
  return tata[a];
}
