#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, c, q;
int fa[N];
vector<int> G[N], col[N];
set<int> s[N];
map<int, int> mp[N];
char op[4];
bool vis[N];
void addedge(int u, int v, int w) {
  G[u].push_back(v);
  col[u].push_back(w);
}
int find(int u) {
  if (u == fa[u]) {
    return fa[u];
  }
  return fa[u] = find(fa[u]);
}
void uniset(int u, int v) {
  if (find(u) == find(v)) {
    return;
  }
  if (s[find(u)].size() < s[find(v)].size()) {
    swap(u, v);
  }
  while (!s[find(v)].empty()) {
    s[find(u)].insert(*s[find(v)].begin());
    s[find(v)].erase(s[find(v)].begin());
  }
  fa[find(v)] = find(u);
}
void dfs(int u) {
  if (vis[u]) {
    return;
  }
  vis[u] = 1;
  for (int i = 0, v, w; i < (int)G[u].size(); i++) {
    v = G[u][i];
    w = col[u][i];
    if (!mp[u][w]) {
      mp[u][w] = v;
    } else {
      uniset(find(mp[u][w]), find(v));
    }
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &c, &q);
  for (int i = 1; i <= n; i++) {
    s[i].insert(i);
    fa[i] = i;
  }
  for (int i = 1, u, v, w; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
    s[u].insert(v);
    s[v].insert(u);
  }
  for (int i = 1; i <= n; i++) {
    dfs(i);
  }
  int u, v, w;
  while (q--) {
    scanf("%s", op);
    if (op[0] == '+') {
      scanf("%d%d%d", &u, &v, &w);
      s[find(u)].insert(v);
      s[find(v)].insert(u);
      if (mp[u][w]) {
        uniset(find(mp[u][w]), find(v));
      } else {
        mp[u][w] = v;
      }
      if (mp[v][w]) {
        uniset(find(mp[v][w]), find(u));
      } else {
        mp[v][w] = u;
      }
    } else {
      scanf("%d%d", &u, &v);
      if (s[find(u)].count(v)) {
        printf("Yes\n");
      } else {
        printf("No\n");
      }
    }
  }
  return 0;
}
