#include <bits/stdc++.h>
using namespace std;
template <typename T>
using v = vector<T>;
const long long inf = 4611686018427387903;
const long double EPS = 1e-10;
void read() {}
template <typename Arg, typename... Args>
void read(Arg& arg, Args&... args) {
  cin >> (arg);
  read(args...);
}
void print() {}
template <typename Arg, typename... Args>
void print(Arg arg, Args... args) {
  cout << (arg) << " ";
  print(args...);
}
long long getInt() {
  long long a;
  cin >> a;
  return a;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 1e5 + 1;
map<long long, long long> col[N];
set<long long> pos[N];
long long repr[N];
long long ffind(long long a) {
  return (a == repr[a]) ? a : repr[a] = ffind(repr[a]);
}
void unite(long long a, long long b) {
  a = ffind(a);
  b = ffind(b);
  if (a == b) return;
  if (pos[a].size() > pos[b].size()) swap(a, b);
  repr[a] = b;
  for (long long i : pos[a]) pos[b].insert(i);
}
void add(long long x, long long y, long long z) {
  if (col[x].count(z)) unite(col[x][z], y);
  if (col[y].count(z)) unite(col[y][z], x);
  pos[ffind(x)].insert(y);
  pos[ffind(y)].insert(x);
  col[x][z] = y;
  col[y][z] = x;
}
void run() {
  long long n, m, c, q;
  read(n, m, c, q);
  for (long long i = (0); i < (n + 1); i++) {
    repr[i] = i;
    pos[i].insert(i);
  }
  for (; m; m--) {
    long long x, y, z;
    read(x, y, z);
    add(x, y, z);
  }
  for (; q; q--) {
    string t;
    cin >> t;
    if (t == "+") {
      long long x, y, z;
      read(x, y, z);
      add(x, y, z);
    } else {
      long long x, y;
      read(x, y);
      x = ffind(x);
      if (pos[x].count(y)) {
        cout << "Yes";
      } else
        cout << "No";
      cout << endl;
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(12);
  run();
}
