#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(int x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const int maxn = 1e6 + 10;
const int inf = 1e9;
const double eps = 1e-8;
const int mod = 1e9 + 7;
map<int, vector<int> > e[maxn];
set<int> r[maxn];
int n, m, c, q, fa[maxn];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (r[x].size() > r[y].size()) swap(x, y);
  fa[x] = y;
  for (auto v : r[x]) r[y].insert(v);
}
void add() {
  int x, y, z;
  read(x), read(y), read(z);
  r[find(x)].insert(y), r[find(y)].insert(x);
  e[x][z].push_back(y), unite(e[x][z][0], y);
  e[y][z].push_back(x), unite(e[y][z][0], x);
}
int main() {
  read(n), read(m), read(c), read(q);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) add();
  for (int i = 1; i <= q; i++) {
    char s[5];
    scanf("%s", s + 1);
    if (s[1] == '+')
      add();
    else {
      int x, y;
      read(x), read(y);
      x = find(x);
      puts((x == find(y) || r[x].count(y)) ? "Yes" : "No");
    }
  }
  return 0;
}
