#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
vector<set<int>> Gpars(MAX);
vector<set<pair<int, int>>> Gcols(MAX);
vector<vector<int>> G(MAX);
vector<vector<int>> classes(MAX);
vector<int> par(MAX);
void merge(int a, int b) {
  int x = par[a], y = par[b];
  if (x == y) return;
  if (classes[x].size() > classes[y].size()) swap(x, y);
  while (!classes[x].empty()) {
    int cur = classes[x].back();
    classes[x].pop_back();
    classes[y].push_back(cur);
    par[cur] = y;
    for (int negh : G[cur]) {
      Gpars[negh].insert(y);
    }
  }
}
void add_edge(int u, int v, int col) {
  G[u].push_back(v);
  G[v].push_back(u);
  Gpars[v].insert(par[u]);
  Gpars[u].insert(par[v]);
  auto itv = Gcols[v].lower_bound(make_pair(col, 0));
  if (itv == Gcols[v].end() || (*itv).first != col) {
    Gcols[v].insert({col, u});
  } else {
    merge(u, (*itv).second);
  }
  auto itu = Gcols[u].lower_bound(make_pair(col, 0));
  if (itu == Gcols[u].end() || (*itu).first != col) {
    Gcols[u].insert({col, v});
  } else {
    merge(v, (*itu).second);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, c, q;
  cin >> n >> m >> c >> q;
  for (int i = 0; i < n; i++) {
    par[i] = i;
    classes[i].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    add_edge(x, y, z);
  }
  while (q--) {
    char cr;
    cin >> cr;
    if (cr == '+') {
      int x, y, z;
      cin >> x >> y >> z;
      x--, y--;
      add_edge(x, y, z);
    } else {
      int x, y;
      cin >> x >> y;
      x--, y--;
      int a = par[x], b = par[y];
      int ok = 0;
      if (a == b) ok = 1;
      if (Gpars[y].find(a) != Gpars[y].end()) ok = 1;
      if (ok)
        cout << "Yes\n";
      else
        cout << "No\n";
    }
  }
  return 0;
}
