#include <bits/stdc++.h>
using namespace std;
const long long int N = 100005;
vector<pair<long long int, long long int> > adj[N];
set<pair<long long int, long long int> > ver[N];
set<long long int> odd[N];
long long int par[N];
long long int n, m, q, c;
void init() {
  for (long long int i = 1; i <= n; i++) {
    par[i] = i;
    for (auto j : adj[i]) odd[i].insert(j.first);
  }
}
long long int find(long long int v) {
  if (v == par[v]) return v;
  return par[v] = find(par[v]);
}
void merge(long long int a, long long int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (odd[a].size() < odd[b].size()) swap(a, b);
    for (auto i : odd[b]) odd[a].insert(i);
    odd[b].clear();
    par[b] = a;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m >> c >> q;
  for (long long int i = 0; i < m; i++) {
    long long int x, y, z;
    cin >> x >> y >> z;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
  }
  init();
  for (long long int i = 1; i <= n; i++) {
    for (auto j : adj[i]) ver[i].insert({j.second, j.first});
    set<pair<long long int, long long int> >::iterator it1, it2;
    for (it1 = ver[i].begin(); it1 != ver[i].end();) {
      it2 = it1;
      it2++;
      pair<long long int, long long int> p = *it1;
      while (it2 != ver[i].end()) {
        pair<long long int, long long int> q = *it2;
        if (p.first != q.first) break;
        merge(p.second, q.second);
        it2++;
      }
      it1 = it2;
    }
  }
  while (q--) {
    char ch;
    cin >> ch;
    if (ch == '+') {
      long long int x, y, z;
      cin >> x >> y >> z;
      pair<long long int, long long int> p;
      if (ver[x].upper_bound({z, -1}) != ver[x].end()) {
        p = *(ver[x].upper_bound({z, -1}));
        if (p.first == z) merge(y, p.second);
      }
      if (ver[y].upper_bound({z, -1}) != ver[y].end()) {
        p = *(ver[y].upper_bound({z, -1}));
        if (p.first == z) merge(x, p.second);
      }
      ver[x].insert({z, y});
      ver[y].insert({z, x});
      long long int a = find(x);
      long long int b = find(y);
      odd[a].insert(y);
      odd[b].insert(x);
    } else {
      long long int x, y;
      cin >> x >> y;
      long long int a = find(x), b = find(y);
      if (a == b || odd[a].find(y) != odd[a].end())
        cout << "Yes\n";
      else
        cout << "No\n";
    }
  }
}
