#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 2001000;
int n,m,Q,mod,fa[N],pw[2][N],u[N],v[N],w[N];
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int find(int x){return fa[x]= fa[x]==x?x:find(fa[x]);}
void merge(int x,int y){
	x=find(x);y=find(y);
	fa[x]=y;
}
int id(int u,int q,int p){return (u-1)*6+q*2+p;}
int main(){
	read(n);read(m);read(Q);read(mod);
	int g=0;
	for(int i=1;i<=m;i++){
		read(u[i]);read(v[i]);read(w[i]);
		g=gcd(g,abs(w[i]-w[1]));
	}
	if(!g) g=mod;
	mod=gcd(3*g,mod);
	int z=w[1]%g;
	for(int i=0;i<n*6;i++) fa[i]=i;
	for(int i=1;i<=m;i++){
		int x=u[i],y=v[i],k=abs(w[i]-z)/g%3;
		for(int q:{0,1,2})
			for(int p:{0,1})
				merge(id(x,q,p),id(y,(q*2+k)%3,p^1)),
				merge(id(y,q,p),id(x,(q*2+k)%3,p^1));
	}
	for(int i=0,now=z;i<mod;i++,now=now*2%mod) pw[i&1][now]=1;
	while(Q--){
		int x,y,len;read(x);read(y);read(len);
		int flag=0;
		for(int q:{0,1,2})
			for(int p:{0,1})
				flag|=find(id(y,0,0))==find(id(x,q,p))&&pw[p][((len+z-q*g)%mod+mod)%mod];
		if(flag) puts("YES");
		else puts("NO");
	}
	return 0;
}
