#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template <typename T>
using VT = vector<T>;
template <typename T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
class UnionFind {
 private:
  vector<int> uni;
  int SIZE;

 public:
  UnionFind(int size) {
    this->uni.resize(size, -1);
    this->SIZE = size;
  }
  UnionFind() {}
  void resize(int size) {
    this->uni.resize(size, -1);
    this->SIZE = size;
  }
  int find(int x) {
    if (uni[x] < 0) return x;
    return uni[x] = find(uni[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (uni[x] > uni[y]) swap(x, y);
    uni[x] += uni[y];
    uni[y] = x;
    this->SIZE--;
    return true;
  }
  int size() { return this->SIZE; }
  int size(int x) { return -uni[find(x)]; }
};
char strbuf[50];
string s, s1, s2;
int N, M, Q;
map<string, int> mp;
UnionFind uf;
int main(void) {
  scanf("%d%d%d", &N, &M, &Q);
  uf.resize(N * 2 + 5);
  for (int(i) = 0; (i) < (N); (i)++) {
    scanf("%s", strbuf);
    s = strbuf;
    mp[s] = i;
  }
  for (int(i) = 0; (i) < (M); (i)++) {
    int t;
    scanf("%d", &t);
    scanf("%s", strbuf);
    s1 = strbuf;
    scanf("%s", strbuf);
    s2 = strbuf;
    if (t == 1) {
      if (uf.same(mp[s1] + N, mp[s2]) || uf.same(mp[s2] + N, mp[s1])) {
        puts("NO");
      } else {
        puts("YES");
        uf.unite(mp[s1], mp[s2]);
        uf.unite(mp[s1] + N, mp[s2] + N);
      }
    } else {
      if (uf.same(mp[s1], mp[s2])) {
        puts("NO");
      } else {
        puts("YES");
        uf.unite(mp[s1], mp[s2] + N);
        uf.unite(mp[s2], mp[s1] + N);
      }
    }
  }
  for (int(i) = 0; (i) < (Q); (i)++) {
    scanf("%s", strbuf);
    s1 = strbuf;
    scanf("%s", strbuf);
    s2 = strbuf;
    if (uf.same(mp[s1], mp[s2])) {
      puts("1");
    } else if (uf.same(mp[s1] + N, mp[s2]) || uf.same(mp[s1] + N, mp[s1])) {
      puts("2");
    } else {
      puts("3");
    }
  }
}
