#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int N = 100010;
int n, m, c, q;
int id[N];
map<int, map<int, int>> mp;
set<int> st[N];
int root(int x) { return id[x] < 0 ? x : id[x] = root(id[x]); }
void join(int u, int v) {
  if ((u = root(u)) == (v = root(v))) return;
  if (st[u].size() < st[v].size()) swap(u, v);
  id[u] += id[v];
  id[v] = u;
  for (auto& i : st[v]) st[u].insert(i);
}
void add(int u, int v, int c) {
  if (mp[u][c])
    join(mp[u][c], v);
  else
    mp[u][c] = v;
  if (mp[v][c])
    join(u, mp[v][c]);
  else
    mp[v][c] = u;
  st[root(u)].insert(v);
  st[root(v)].insert(u);
}
int que(int u, int v) { return root(u) == root(v) || st[root(u)].count(v); }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  ;
  memset(id, -1, sizeof(id));
  cin >> n >> m >> c >> q;
  for (int i = 1, _c = m; i <= _c; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    add(u, v, c);
  }
  for (int i = 1, _c = q; i <= _c; ++i) {
    char t;
    int u, v;
    cin >> t >> u >> v;
    if (t == '+') {
      int c;
      cin >> c;
      add(u, v, c);
    } else
      cout << (que(u, v) ? "Yes" : "No") << "\n";
  }
}
