#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
using namespace std;
const int N = 1e5 + 5;
int n, m, c, q;
int dsu[N];
map<int, int> edge[N];
set<int> path[N];
int ufds(int u) { return dsu[u] = dsu[u] == u ? u : ufds(dsu[u]); }
void join(int u, int v) {
  u = ufds(u), v = ufds(v);
  if (u != v) {
    dsu[v] = u;
    if (path[u].size() < path[v].size()) {
      swap(path[u], path[v]);
    }
    path[u].insert(path[v].begin(), path[v].end());
  }
}
void create(int u, int v, int cc) {
  if (edge[u].count(cc)) {
    join(v, edge[u][cc]);
  } else {
    edge[u][cc] = v;
  }
  if (edge[v].count(cc)) {
    join(u, edge[v][cc]);
  } else {
    edge[v][cc] = u;
  }
  path[ufds(u)].insert(v);
  path[ufds(v)].insert(u);
}
int main() {
  scanf("%d%d%d%d", &n, &m, &c, &q);
  iota(dsu, dsu + n, 0);
  for (int i = 0; i < n; i++) {
    path[i].insert(i);
  }
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x--, y--;
    create(x, y, z);
  }
  for (int i = 0; i < q; i++) {
    char ch[2];
    int x, y;
    scanf("%s%d%d", ch, &x, &y);
    x--, y--;
    if (ch[0] == '+') {
      int z;
      scanf("%d", &z);
      create(x, y, z);
    } else {
      puts(path[ufds(x)].count(y) ? "Yes" : "No");
    }
  }
}
