#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chmin(T &a, const T &val) {
  if (a > val) a = val;
}
template <class T>
inline void chmax(T &a, const T &val) {
  if (a < val) a = val;
}
template <class T>
long long sqr(T a) {
  return 1ll * a * a;
}
template <class T>
void compress(T &a) {
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
}
const double pi = acos(-1.00);
const double eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
int n, m, Q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> Q;
  vector<string> memo(n);
  for (string &s : memo) cin >> s;
  sort(memo.begin(), memo.end());
  vector<int> lab(2 * n + 1, -1);
  auto Get = [&](int u) {
    while (lab[u] > 0) u = lab[u];
    return u;
  };
  auto Union = [&](int u, int v) {
    if (lab[u] > lab[v]) swap(u, v);
    lab[u] += lab[v];
    lab[v] = u;
  };
  while (m--) {
    int type;
    cin >> type;
    string s, t;
    cin >> s >> t;
    int u = lower_bound(memo.begin(), memo.end(), s) - memo.begin() + 1;
    int v = lower_bound(memo.begin(), memo.end(), t) - memo.begin() + 1;
    if (type == 1) {
      if (Get(u) == Get(n + v))
        cout << "NO\n";
      else {
        cout << "YES\n";
        int x = Get(u);
        int y = Get(v);
        if (x != y) Union(x, y);
        x = Get(n + u);
        y = Get(n + v);
        if (x != y) Union(x, y);
      }
    } else {
      if (Get(u) == Get(v))
        cout << "NO\n";
      else {
        cout << "YES\n";
        int x = Get(u);
        int y = Get(n + v);
        if (x != y) Union(x, y);
        x = Get(n + u);
        y = Get(v);
        if (x != y) Union(x, y);
      }
    }
  }
  while (Q--) {
    string s, t;
    cin >> s >> t;
    int u = lower_bound(memo.begin(), memo.end(), s) - memo.begin() + 1;
    int v = lower_bound(memo.begin(), memo.end(), t) - memo.begin() + 1;
    if (Get(u) == Get(v))
      cout << 1 << '\n';
    else if (Get(u) == Get(n + v))
      cout << 2 << '\n';
    else
      cout << 3 << '\n';
  }
  return 0;
}
