#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 1000003;
template<typename T>
inline void read(T &x){
    int ch = getchar(); x = 0;
    for(;ch < '0' || ch > '9';ch = getchar());
    for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
}
int n, m, q, z, g, mod, u[N], v[N], c[N], fa[N], h[N];
bool pr[2][N];
inline int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
inline int id(int x, int p, int q){return (x - 1) * 6 + p * 3 + q;}
inline int getfa(int x){while(x != fa[x]) x = fa[x] = fa[fa[x]]; return x;}
inline void comb(int x, int y){
    x = getfa(x); y = getfa(y);
    if(x != y){
        if(h[x] < h[y]) swap(x, y);
        fa[y] = x; h[x] += h[x] == h[y];
    }
}
inline int qmo(int x){return x + ((x >> 31) & mod);}
int main(){
    read(n); read(m); read(q); read(mod);
    for(Rint i = 1;i <= m;++ i){
        read(u[i]); read(v[i]); read(c[i]);
        g = gcd(g, abs(c[i] - c[1]));
    }
    if(!g) g = mod; mod = gcd(3 * g, mod); int z = c[1] % g;
    for(Rint i = 0;i < 6 * n;++ i) fa[i] = i;
    for(Rint i = 1;i <= m;++ i){
        int t = (c[i] - z) / g;
        for(Rint p = 0;p < 2;++ p)
            for(Rint q = 0;q < 3;++ q){
                comb(id(u[i], p, q), id(v[i], !p, (2 * q + t) % 3));
                comb(id(v[i], p, q), id(u[i], !p, (2 * q + t) % 3));
            }
    }
    for(Rint i = 0, t = z;i < (mod << 1);++ i, t = qmo(2 * t - mod)) pr[i & 1][t] = true;
    while(q --){
        int s, t, r; read(s); read(t); read(r);
        bool ans = 0;
        for(Rint p = 0;p < 2;++ p)
            for(Rint q = 0;q < 3;++ q)
                if(getfa(id(t, 0, 0)) == getfa(id(s, p, q))) ans |= pr[p][(r + z + (3 - q) * g) % mod];
        puts(ans ? "YES" : "NO");
    }
}