#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 +c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
const int maxn = 5e5 + 5,maxm = 1e6 + 5;;

int N,M,Q,MOD,f[maxn],t[maxn],v[maxn];
int fa[maxm * 6],z,g;
bool able[2][maxm];
int id(int u,int p,int q) {
    return (u - 1) * 6 + p * 3 + q + 1;
}
int gcd(int a,int b) {
    return b == 0 ? a : gcd(b,a % b);
}
int getfa(int u) {
    return u == fa[u] ? u : fa[u] = getfa(fa[u]);
}
void Merge(int u,int v) {
    fa[getfa(u)] = getfa(v);
}
void Init() {
    read(N);read(M);read(Q);read(MOD);
    read(f[1]);read(t[1]);read(v[1]);
    g = MOD;
    for(int i = 2 ; i <= M ; ++i) {
    read(f[i]);read(t[i]);read(v[i]);
    g = gcd(g,abs(v[i] - v[1]));
    }
    MOD = gcd(MOD,3 * g);
    z = v[1] % g;
    int T = id(N,1,2);
    for(int i = 1 ; i <= T; ++i) fa[i] = i;
    for(int i = 1 ; i <= M ; ++i) {
    int w = (v[i]-z )/ g % 3;
    for(int p = 0 ; p < 2 ; ++p) {
        for(int q = 0 ; q < 3 ; ++q) {
        Merge(id(f[i],p,q),id(t[i],p ^ 1,(q * 2 + w) % 3));
        Merge(id(t[i],p,q),id(f[i],p ^ 1,(q * 2 + w) % 3));
        }
    }
    }
    for(int i = 0 , j = z ; i < MOD ; ++i , j = j * 2 % MOD) able[i & 1][j] = 1;
}
void Solve() {
    int s,t,r;
    for(int i = 1 ; i <= Q ; ++i) {
    read(s);read(t);read(r);
    bool res = 0;
    for(int p = 0 ; p < 2 ; ++p) {
        for(int q = 0 ; q < 3 ; ++q) {
        if(getfa(id(t,0,0)) == getfa(id(s,p,q))) {
            if(able[p][(r + z + (3 - q) * g) % MOD]) res = 1;
        }
        }
    }
    if(res) puts("YES");
    else puts("NO");
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}