#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
set<int> st[N];
map<int, int> mp[N];
int n, m, q, fa[N];
inline int find(int x) {
  while (x != fa[x]) x = fa[x] = fa[fa[x]];
  return x;
}
inline void merge(int x, int y) {
  int u = find(x), v = find(y);
  if (u == v) return;
  if (st[u].size() < st[v].size()) u ^= v ^= u ^= v;
  fa[v] = u;
  for (int i : st[v]) st[u].insert(i);
  st[v].clear();
}
inline void addedge(int u, int v, int c) {
  st[find(u)].insert(v);
  if (mp[u].count(c)) {
    int x = mp[u][c];
    merge(v, x);
  } else
    mp[u][c] = v;
}
int main() {
  scanf("%d%d%*d%d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  while (m--) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    addedge(u, v, c), addedge(v, u, c);
  }
  while (q--) {
    char op[3];
    int u, v, c;
    scanf("%s%d%d", op, &u, &v);
    if (*op == '+') {
      scanf("%d", &c);
      addedge(u, v, c), addedge(v, u, c);
    } else {
      int x = find(u), y = find(v);
      if (x == y || st[x].count(v))
        puts("Yes");
      else
        puts("No");
    }
  }
  return 0;
}
