//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxmod = 1000111;
struct dsu
{
	int f[maxmod*6];
	void init(int N)
	{
		for (int i=0; i<N; i++) f[i] = i;
	}
	int gf(int x) {return f[x]==x?x:f[x]=gf(f[x]);}
	void un(int x, int y)
	{
		x = gf(x); y = gf(y);
		f[x] = y;
	}
}D0, D1;
int n, m, Q, M, C, g;
vector<int> vl;
vector<pair<pair<int,int>,int> > E;
int gr[maxmod][2];
void prework()
{
	D0.init(M+M);
	int gn = 0;
	for (int i=0; i<M; i++)
	{
		D0.un(i, (i+i)%M+M);
		D0.un(i+M, (i+i)%M);
	}
	D1.init(n*6);
	for (auto e : E)
	{
		int x = e.FF.FF;
		int y = e.FF.SS;
		int w = e.SS;
		int t = ((w-C+M)%M)/g;
//		cerr<<x<<"-"<<y<<" "<<w<<endl;
		for (int i=0; i<3; i++)
		{
			int j = (i*2+t)%3;
//			cerr<<"un:"<<x<<"-"<<y<<" "<<i<<"-"<<j<<endl;
			D1.un((i*2)*n+x, (j*2+1)*n+y);
			D1.un((i*2+1)*n+x, (j*2)*n+y);
			
			D1.un((i*2)*n+y, (j*2+1)*n+x);
			D1.un((i*2+1)*n+y, (j*2)*n+x);
		}
	}
//	for (int i=1; i<=6*n; i++) cerr<<D1.gf(i)<<" "; cerr<<endl;
}
int main()
{
	getii(n, m);
	getii(Q, M);
	for (int i=1; i<=m; i++)
	{
		int x, y, l;
		getiii(x, y, l);
		vl.PB(l);
		E.PB(MP(MP(x, y), l));
	}
	sort(vl.begin(), vl.end());
	int new_M = M;
	g = M;
	for (int i=1; i<vl.size(); i++)
	{
		g = __gcd(g, vl[i]-vl[0]);
		new_M = __gcd(new_M, 3*(vl[i]-vl[0]));
	}
	M = new_M;
	for (auto &x : E) x.SS %= M;
	C = E[0].SS%g;
//	cerr<<"g="<<g<<" M="<<M<<" C="<<C<<endl;
	prework();
	for (int i=1; i<=Q; i++)
	{
		int S, T, R;
		getiii(S, T, R);
		bool ans = 0;
		for (int p=0; p<2; p++)
		{
			for (int t=0; t<3; t++)
			{
//				cerr<<"D1: ("<<t<<","<<p<<","<<T<<")-(0,0,"<<S<<") D0: ("<<p<<","<<((3-t)*g+C)%M<<")-(0,"<<(R+C)%M<<")"<<endl;
				if (D1.gf((t*2+p)*n+T)==D1.gf(S)&&D0.gf(((3-t)*g+C)%M+M*p)==D0.gf((R+C)%M))
				{
//					cerr<<"p="<<p<<" t="<<t<<endl;
					ans = 1;
				}
			}
		}
		if (ans) puts("YES"); else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 15928