#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MOD = 998244353;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
int par[100010];
vector<int> vec[100010][2];
int col[100010];
int fnd(int u) { return (par[u] == -1) ? u : (par[u] = fnd(par[u])); }
int sz(int u) { return ((int)vec[u][0].size() + (int)vec[u][1].size()); }
void mrg(int u, int v) {
  u = fnd(u), v = fnd(v);
  if (sz(u) < sz(v)) swap(u, v);
  for (auto x : vec[v][0]) col[x] = 0, vec[u][0].push_back(x), 42;
  for (auto x : vec[v][1]) col[x] = 1, vec[u][1].push_back(x), 42;
  vec[v][0].clear();
  vec[v][1].clear();
  par[v] = u;
}
int32_t main() {
  ios::sync_with_stdio(!cin.tie(NULL));
  int n, m, q;
  cin >> n >> m >> q;
  map<string, int> mp;
  string s;
  for (int i = 0; i < n; i++)
    par[i] = -1, cin >> s, mp[s] = i, col[i] = 0, vec[i][0].push_back(i);
  int u, v;
  int t;
  for (int i = 0; i < m; i++) {
    cin >> t;
    cin >> s;
    u = mp[s];
    cin >> s;
    v = mp[s];
    42;
    if (fnd(u) == fnd(v) and
        ((t == 1 and col[u] != col[v]) or (t == 2 and col[u] == col[v]))) {
      cout << "NO\n";
      continue;
    }
    if (fnd(u) == fnd(v)) {
      cout << "YES\n";
      continue;
    }
    if (sz(fnd(u)) < sz(fnd(v))) swap(u, v);
    if ((t == 2 and col[u] == col[v]) or (t == 1 and col[u] != col[v]))
      swap(vec[fnd(v)][0], vec[fnd(v)][1]);
    mrg(u, v);
    42;
    cout << "YES\n";
  }
  for (int i = 0; i < q; i++) {
    cin >> s;
    u = mp[s];
    cin >> s;
    v = mp[s];
    if (fnd(u) != fnd(v))
      cout << "3\n";
    else if (col[u] == col[v])
      cout << "1\n";
    else
      cout << "2\n";
  }
}
