#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
inline bool read(T &x) {
  int second = getchar();
  int sgn = 1;
  while (~second && second < '0' || second > '9') {
    if (second == '-') sgn = -1;
    second = getchar();
  }
  for (x = 0; ~second && '0' <= second && second <= '9'; second = getchar())
    x = x * 10 + second - '0';
  x *= sgn;
  return ~second;
}
const int INF = 2000000009;
const int MX = 100005;
const double EPS = 1e-9;
const int MOD = 1000000007;
vector<pair<int, int> > g[MX];
int par[MX];
set<int> st[MX];
set<pair<int, int> > s[MX];
void init() {
  for (int i = 0; i < MX; i++) {
    par[i] = i;
  }
}
int findParent(int x) { return x == par[x] ? x : par[x] = findParent(par[x]); }
void Union(int u, int v) {
  u = findParent(u);
  v = findParent(v);
  if (u == v) return;
  if ((int)st[u].size() < (int)st[v].size()) swap(u, v);
  par[v] = u;
  for (int p : st[v]) st[u].insert(p);
}
void addEdge(int u, int v, int second) {
  st[findParent(u)].insert(v);
  st[findParent(v)].insert(u);
  set<pair<int, int> >::iterator it;
  it = s[v].upper_bound(pair<int, int>(second - 1, INF));
  if (it != s[v].end() && it->first == second) {
    Union(u, it->second);
  } else
    s[v].insert(pair<int, int>(second, u));
  it = s[u].upper_bound(pair<int, int>(second - 1, INF));
  if (it != s[u].end() && it->first == second) {
    Union(v, it->second);
  } else
    s[u].insert(pair<int, int>(second, v));
}
int main() {
  init();
  int n = ({
    int a;
    read(a);
    a;
  }),
      m = ({
        int a;
        read(a);
        a;
      }),
      second = ({
        int a;
        read(a);
        a;
      }),
      q = ({
        int a;
        read(a);
        a;
      });
  while (m--) {
    int u = ({
      int a;
      read(a);
      a;
    }),
        v = ({
          int a;
          read(a);
          a;
        }),
        second = ({
          int a;
          read(a);
          a;
        });
    addEdge(u, v, second);
  }
  while (q--) {
    char ch;
    scanf("%c", &ch);
    if (ch == '+') {
      int u = ({
        int a;
        read(a);
        a;
      }),
          v = ({
            int a;
            read(a);
            a;
          }),
          second = ({
            int a;
            read(a);
            a;
          });
      addEdge(u, v, second);
    } else {
      int u = ({
        int a;
        read(a);
        a;
      }),
          v = ({
            int a;
            read(a);
            a;
          });
      int pu = findParent(u), pv = findParent(v);
      if (pu == pv || st[pu].find(v) != st[pu].end())
        printf("Yes\n");
      else
        printf("No\n");
    }
  }
  return 0;
}
