#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long int inf = -1e18;
const int MOD = 1e9 + 7;
string s, ss;
map<string, long long int> mp;
long long int p[N], opp[N];
long long int root(long long int x) {
  while (x != p[x]) {
    p[x] = p[p[x]];
    x = p[x];
  }
  return x;
}
void join(long long int x, long long int y) { p[root(y)] = p[root(x)]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  for (int i = 1; i < N; i++) p[i] = i;
  long long int n, m, q, t, rt_1, rt_2;
  cin >> n >> m >> q;
  for (int i = 0; i < n; i += 1) {
    cin >> s;
    mp[s] = i + 1;
  }
  for (int i = 0; i < m; i += 1) {
    cin >> t >> s >> ss;
    rt_1 = root(mp[s]);
    rt_2 = root(mp[ss]);
    if (t == 1) {
      if (rt_1 == rt_2) {
        cout << "YES\n";
      } else {
        if (root(opp[rt_1]) == root(rt_2) || root(opp[rt_2]) == root(rt_1)) {
          cout << "NO\n";
        } else {
          join(rt_1, rt_2);
          if (!opp[rt_1])
            opp[rt_1] = root(opp[rt_2]);
          else if (!opp[rt_2])
            opp[rt_2] = root(opp[rt_1]);
          if (root(opp[rt_1]) != root(opp[rt_2])) join(opp[rt_1], opp[rt_2]);
          cout << "YES\n";
        }
      }
    } else {
      if (rt_1 == rt_2) {
        cout << "NO\n";
      } else {
        if (opp[rt_1] && root(opp[rt_1]) != root(rt_2)) {
          join(opp[rt_1], rt_2);
        } else
          opp[rt_1] = root(rt_2);
        if (opp[rt_2] && root(opp[rt_2]) != root(rt_1)) {
          join(opp[rt_2], rt_1);
        } else
          opp[rt_2] = root(rt_1);
        cout << "YES\n";
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    cin >> s >> ss;
    rt_1 = root(mp[s]);
    rt_2 = root(mp[ss]);
    if (rt_1 == rt_2) {
      cout << 1 << "\n";
    } else if (root(opp[rt_2]) == root(rt_1) || root(opp[rt_1]) == root(rt_2)) {
      cout << 2 << "\n";
    } else
      cout << 3 << "\n";
  }
  return 0;
}
