#include <bits/stdc++.h>
using namespace std;
struct DSU {
  int N;
  vector<int> component, weight;
  DSU(int n) {
    N = n;
    component.resize(n + 1);
    weight.resize(n + 1);
    for (int i = 0; i <= N; i++) {
      component[i] = i;
      weight[i] = 1;
    }
  }
  int root(int first) {
    while (component[first] != first) {
      component[first] = component[component[first]];
      first = component[first];
    }
    return first;
  }
  int merge(int first, int second) {
    int val = 0;
    if (same(first, second)) return 0;
    first = root(first);
    second = root(second);
    if (weight[first] < weight[second]) {
      swap(first, second);
      val = 1;
    }
    weight[first] += weight[second];
    component[second] = first;
    return val;
  }
  bool same(int first, int second) { return root(first) == root(second); }
};
const int maxn = 1e5 + 4;
int n, mm, c, q;
set<int> s[maxn];
map<int, int> m[maxn];
DSU d(maxn);
vector<int> adjlist[maxn];
void connect(int first, int second, int color) {
  int xpar = d.root(first), ypar = d.root(second);
  adjlist[xpar].push_back(second);
  adjlist[ypar].push_back(first);
  s[second].insert(xpar);
  s[first].insert(ypar);
  if (m[first][color] != 0) {
    int neighbor = m[first][color];
    int npar = d.root(neighbor);
    if (npar != ypar) {
      int op = d.merge(npar, ypar);
      if (op) swap(npar, ypar);
      for (auto u : adjlist[ypar]) {
        adjlist[npar].push_back(u);
        s[u].erase(ypar);
        s[u].insert(npar);
      }
    }
  }
  m[first][color] = second;
  xpar = d.root(first);
  ypar = d.root(second);
  if (m[second][color] != 0) {
    int neighbor = m[second][color];
    int npar = d.root(neighbor);
    if (npar != xpar) {
      int op = d.merge(npar, xpar);
      if (op) swap(npar, xpar);
      for (auto u : adjlist[xpar]) {
        adjlist[npar].push_back(u);
        s[u].erase(xpar);
        s[u].insert(npar);
      }
    }
  }
  m[second][color] = first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> mm >> c >> q;
  for (int i = 1; i <= n; i++) s[i].insert(i);
  for (int i = 1; i <= mm; i++) {
    int first, second, w;
    cin >> first >> second >> w;
    connect(first, second, w);
  }
  while (q--) {
    char t;
    int first, second;
    cin >> t >> first >> second;
    if (t == '?') {
      if (d.same(first, second) ||
          s[second].find(d.root(first)) != s[second].end())
        cout << "Yes\n";
      else
        cout << "No\n";
    } else {
      int col;
      cin >> col;
      connect(first, second, col);
    }
  }
  return 0;
}
