#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
set<int> s[N];
map<int, int> mp[N];
int fa[N], n, m, c, q;
char opt[3];
int finds(int x) {
  if (fa[x] == x) return fa[x];
  fa[x] = finds(fa[x]);
  return fa[x];
}
void merge(int x, int y) {
  int fx = finds(x), fy = finds(y);
  if (fx == fy) return;
  if (s[fx].size() < s[fy].size()) swap(fx, fy);
  fa[fy] = fx;
  for (int i : s[fy]) s[fx].insert(i);
  s[fy].clear();
}
void addedge(int x, int y, int col) {
  s[finds(x)].insert(y);
  if (mp[x].count(col)) {
    int v = mp[x][col];
    merge(y, v);
  } else
    mp[x][col] = y;
}
int main() {
  scanf("%d%d%*d%d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= m; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    addedge(x, y, z);
    addedge(y, x, z);
  }
  for (int i = 1; i <= q; ++i) {
    scanf("%s", opt);
    int x, y;
    scanf("%d%d", &x, &y);
    if (opt[0] == '+') {
      int z;
      scanf("%d", &z);
      addedge(x, y, z);
      addedge(y, x, z);
    } else {
      int fx = finds(x), fy = finds(y);
      if ((fx == fy) || (s[fx].count(y))) {
        puts("Yes");
      } else
        puts("No");
    }
  }
  return 0;
}
