#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, c, q;
int fa[N], siz[N];
multiset<int> pbl[N];
vector<int> e[N], vex[N];
map<int, int> g[N];
int find(int x) {
  for (; fa[x] != x; x = fa[x])
    ;
  return x;
}
void reconsitution(vector<int> &v, vector<int> &x, int rt, int bt) {
  for (int i = 0; i < (int)v.size(); i++) {
    int u = v[i];
    for (int j = 0; j < (int)e[u].size(); j++) {
      int v = e[u][j];
      pbl[v].erase(pbl[v].find(rt));
      pbl[v].insert(bt);
    }
  }
  x.insert(x.end(), v.begin(), v.end());
  v.clear();
  return;
}
void merge(int u, int v) {
  u = find(u), v = find(v);
  if (u == v) return;
  if (siz[u] > siz[v]) swap(u, v);
  fa[u] = v, siz[v] += siz[u];
  reconsitution(vex[u], vex[v], u, v);
  return;
}
void adde(int u, int v, int w) {
  e[u].push_back(v);
  pbl[v].insert(find(u));
  if (!g[u].count(w)) return void(g[u][w] = v);
  int l = g[u][w];
  merge(v, l);
  return;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &c, &q);
  for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1, vex[i].push_back(i);
  int u, v, w;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    adde(u, v, w), adde(v, u, w);
  }
  char op;
  for (int i = 1; i <= q; i++) {
    scanf(" %c ", &op);
    if (op == '+') {
      scanf("%d%d%d", &u, &v, &w);
      adde(u, v, w);
      adde(v, u, w);
    } else {
      scanf("%d%d", &u, &v);
      u = find(u);
      if (find(v) == u)
        printf("Yes\n");
      else if (pbl[v].count(u))
        printf("Yes\n");
      else
        printf("No\n");
    }
  }
  return 0;
}
