RT
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define ls(x) x<<1
#define rs(x) x<<1|1
#define N 200005
using namespace std;
int n,m,k;
struct node{
int u,v;
};
vector<node> mp[N<<2];
int tree[N<<2],fa[N*2];
#define ls(x) x<<1
#define rs(x) x<<1|1
void update(int l,int r,int root,node k,int ll,int rr){
if(l>=ll&&r<=rr){
mp[root].push_back(k);
return ;
}
int mid=(l+r)>>1;
if(ll<=mid)
update(l,mid,ls(root),k,ll,rr);
if(rr>mid)
update(mid+1,r,rs(root),k,ll,rr);
return ;
}
int findf(int k){
if(fa[k]==k)
return k;
return findf(fa[k]);
}
struct eee{
int u,f;
};
int cnt=0,cnt2=0,he[N*2];
eee sta[N*2],st[N*2];
void merge(int x,int y){
int fx=findf(x),fy=findf(y);
if(fx==fy)return ;
if(he[x]<he[y]){
sta[++cnt]=(eee){
fx,fx
};
fa[fx]=fy;
}
else{
if(he[x]>he[y]){
sta[++cnt]=(eee){
fy,fy
};
fa[fy]=fx;
}
else{
sta[++cnt]=(eee){
fx,fx
};
fa[fx]=fy;
st[++cnt2]=(eee){
fy,he[fy]
};
++he[fy];
}
}
}
void hui(int yao,int yao2){
while(1){
if(cnt==yao)break;
fa[sta[cnt].u]=sta[cnt].f;
--cnt;
}
while(1){
if(cnt2==yao2)break;
he[st[cnt2].u]=st[cnt2].f;
--cnt2;
}
}
void sol(int l,int r,int root){
int you=cnt,you2=cnt2;
for(int i=0;i<mp[root].size();++i){
int u=mp[root][i].u,v=mp[root][i].v;
if(findf(u)==findf(v)){
hui(you,you2);
for(int j=l;j<=r;++j){
puts("No");
}
return ;
}
merge(u,v+n);
merge(v,u+n);
}
if(l==r){
puts("Yes");
return ;
}
int mid=(l+r)>>1;
sol(l,mid,ls(root));
sol(mid+1,r,rs(root));
hui(you,you2);
}
int main(){
// freopen("P3178_1.in","r",stdin);
// freopen("eee.out","w",stdout);
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=2*n;++i){
fa[i]=i;
he[i]=1;
}
for(int i=1;i<=m;++i){
int x,y,l,r;
scanf("%d%d%d%d",&x,&y,&l,&r);
update(1,k,1,(node){
x,y
},l+1,r);
}
sol(1,k,1);
return 0;
}