#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int ant[N];
int par[N];
map<string, int> mp;
int n, m, q;
void pre() {
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }
  for (int i = 0; i < n; i++) {
    ant[i] = -1;
  }
}
int get(int v) {
  if (v == par[v]) {
    return v;
  }
  return par[v] = get(par[v]);
}
void input() {
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    mp[s] = i;
  }
}
void build() {
  for (int i = 0; i < m; i++) {
    int t;
    string s1, s2;
    cin >> t >> s1 >> s2;
    int u = mp[s1];
    int v = mp[s2];
    if (t == 1) {
      u = get(u);
      v = get(v);
      if (ant[u] != -1 && get(ant[u]) == v) {
        cout << "NO" << endl;
        continue;
      }
      cout << "YES" << endl;
      par[u] = v;
      if (ant[u] != -1 && ant[v] != -1) {
        u = get(ant[u]);
        v = get(ant[v]);
        par[u] = v;
      }
      if (ant[v] == -1 && ant[u] != -1) {
        ant[v] = get(ant[u]);
      }
    }
    if (t == 2) {
      u = get(u);
      v = get(v);
      if (u == v) {
        cout << "NO" << endl;
        continue;
      }
      cout << "YES" << endl;
      if (ant[v] != -1) {
        par[u] = get(ant[v]);
      }
      if (ant[u] != -1) {
        par[v] = get(ant[u]);
      }
      ant[u] = get(v);
      ant[v] = get(u);
    }
  }
}
int main() {
  input();
  pre();
  build();
  for (int i = 0; i < q; i++) {
    string s, t;
    cin >> s >> t;
    int u = mp[s];
    int v = mp[t];
    u = get(u);
    v = get(v);
    if (u == v) {
      cout << 1 << endl;
      continue;
    }
    if (ant[u] != -1 && get(ant[u]) == v) {
      cout << 2 << endl;
      continue;
    }
    cout << 3 << endl;
  }
}
