#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& v) {
  out << "[";
  for (int i = 0; i < v.size(); ++i) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << "]";
}
const int N = 1e5 + 6;
const string yes = "Yes", no = "No";
vector<vector<pair<int, int>>> adj(N);
vector<int> par(N);
vector<set<int>> sets(N);
vector<map<int, int>> adj1(N);
int parent(int v) {
  if (par[v] == v)
    return v;
  else
    return par[v] = parent(par[v]);
}
void merge(int from, int to) {
  if (from == to) return;
  from = parent(from);
  to = parent(to);
  if (sets[to].size() > sets[from].size()) {
    sets[to].insert(sets[from].begin(), sets[from].end());
    set<int>().swap(sets[from]);
  } else {
    sets[from].insert(sets[to].begin(), sets[to].end());
    set<int>().swap(sets[to]);
    sets[from].swap(sets[to]);
  }
}
void dsu(int u, int v) {
  merge(parent(u), parent(v));
  par[u] = parent(par[v]);
}
void add(int x, int y, int color) {
  if (adj1[y][color]) {
    dsu(parent(x), parent(adj1[y][color]));
  }
  if (adj1[x][color]) {
    dsu(parent(y), parent(adj1[x][color]));
  }
  adj1[x][color] = y;
  adj1[y][color] = x;
  sets[parent(x)].insert(y);
  sets[parent(y)].insert(x);
}
int main(int argc, char const* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m, c, q;
  cin >> n >> m >> c >> q;
  iota(par.begin(), par.end(), 0);
  for (int i = (0); i < (m); ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    add(x, y, z);
  }
  for (int i = (0); i < (q); ++i) {
    char c;
    int x, y, z;
    cin >> c;
    if (c == '+') {
      cin >> x >> y >> z;
      add(x, y, z);
    } else {
      cin >> x >> y;
      if (parent(x) == parent(y)) {
        cout << yes << endl;
      } else if (sets[parent(x)].count(y) == 1) {
        cout << yes << endl;
      } else {
        cout << no << endl;
      }
    }
  }
  return 0;
}
