#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N=1e5 + 5,B=21;
int v[N],n,m,x;

struct node {

	ll sum;
	int l[B],r[B];
	node(){
		sum=0;
		memset(l,-1,sizeof l);
		for(int i=0;i < B;i++)
			r[i]=n;
	}
} seg[4 * N];

node merge(const node &nl,const node & nr,int &mid,int l,int r){

	node ret;
	ret.sum=nl.sum + nr.sum;
	for(int i=0;i < B;i++){
		ret.l[i]=max(max(nl.l[i],(nl.r[i] != n ? nl.r[i] : -1)),ret.l[i]);
		ret.r[i]=min(min(nr.r[i],(nr.l[i] != -1 ? nr.l[i] : n)),ret.r[i]);
	}
	vector<pair<int, int> > L,R;
	int d=v[mid];
	for(int i=0;i < B;i++){
		if(((1 << i) & d) == 0){
			if(ret.l[i] != -1) L.pb({ ret.l[i], i }), d|=1 << i;
			if(ret.r[i] != n) R.pb({ ret.r[i], i });
		}
	}
	L.pb({ mid, 0 });
	sort(L.begin(),L.end()), sort(R.begin(),R.end());
	int rin=0,a=l,d2=v[mid + 1],b=mid + 1;
	if(!R.size()) b=r;
	else if(R[0].fi != mid + 1) b=R[0].fi - 1;

	for(int i=0,in,bt,c=0;i < L.size();i++){
		in=L[i].fi, bt=L[i].se;
		if(i != L.size() - 1 && L[i].fi == L[i + 1].fi){
			c|=1 << bt;
			continue;
		}
		while(rin < R.size() && ((d | d2) | v[R[rin].fi]) < x){
			d2|=v[R[rin].fi];
			rin++;
			if(rin == R.size()) b=r;
			else b=R[rin].fi - 1;
		}
		if((d | d2) < x) ret.sum+=ll(in - a + 1) * (b - mid);
		a=in + 1;
		d^=1 << bt;
		d^=c;
		c=0;
	}
	return ret;

}

void update(int n,int l,int r,int s,int e){

	if(r < s || l > e) return;
	if(l >= s && r <= e){
		if(v[l] < x) seg[n].sum=1;
		else seg[n].sum=0;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	update(n * 2 + 1,l,mid,s,e);
	update(n * 2 + 2,mid + 1,r,s,e);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);

}

void build(int n,int l,int r){

	if(l == r){
		if(v[l] < x) seg[n].sum=1;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	build(n * 2 + 1,l,mid);
	build(n * 2 + 2,mid + 1,r);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);
}

node get(int n,int l,int r,int s,int e){

	if(r < s || l > e) return node();
	if(l >= s && r <= e){
		return seg[n];
	}
	int mid=(l + r) >> 1;
	node nl=get(n * 2 + 1,l,mid,s,e);
	node nr=get(n * 2 + 2,mid + 1,r,s,e);
	if(mid < s) return nr;
	if(mid + 1 > e) return nl;
	return merge(nl,nr,mid,max(l,s),min(r,e));
}

int main(){

//	freopen("in.txt","r",stdin);

	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i < n;i++){
		scanf("%d",v + i);
	}
	build(0,0,n - 1);
	while(m--){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t == 1){
			v[--a]=b;
			update(0,0,n - 1,a,a);
		}
		if(t == 2){
			ll len=b - a + 1;
			ll ans=(len * (len + 1)) / 2;
			a--, b--;
			ans-=get(0,0,n - 1,a,b).sum;
			printf("%lld\n",ans);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N=1e5 + 5,B=21;
int v[N],n,m,x;

struct node {

	ll sum;
	int l[B],r[B];
	node(){
		sum=0;
		memset(l,-1,sizeof l);
		for(int i=0;i < B;i++)
			r[i]=n;
	}
} seg[4 * N];

node merge(const node &nl,const node & nr,int &mid,int l,int r){

	node ret;
	ret.sum=nl.sum + nr.sum;
	for(int i=0;i < B;i++){
		ret.l[i]=max(max(nl.l[i],(nl.r[i] != n ? nl.r[i] : -1)),ret.l[i]);
		ret.r[i]=min(min(nr.r[i],(nr.l[i] != -1 ? nr.l[i] : n)),ret.r[i]);
	}
	int d=v[mid],dd=v[mid];
	vector<pair<int, int> > L,R;
	for(int j=0;j < B;j++){
		int in=-1,x=0;
		for(int i=0;i < B;i++){
			if(((1 << i) & d) == 0) in=max(in,ret.l[i]);
		}
		if(in == -1) break;
		x=v[in] & (~d);
		d|=x;
		L.pb({ in, x });
	}
	L.pb({ mid, 0 });
	sort(L.begin(),L.end());

	for(int j=0;j < B;j++){
		int in=n,x=0;
		for(int i=0;i < B;i++){
			if(((1 << i) & dd) == 0) in=min(in,ret.r[i]);
		}
		if(in == n) break;
		x=v[in] & (~dd);
		dd|=x;
		R.pb({ in, x });
	}

	int a=l,b=mid + 1,d2=v[mid +1],rin=0;
	if(!R.size()) b=r;
	else if(R[0].fi != mid + 1) b=R[0].fi - 1;
	for(int i=0,in,bt;i < L.size();i++){
		in=L[i].fi, bt=L[i].se;
		while(rin < R.size() && (d | d2 | R[rin].se) < x){
			d2|=R[rin].se;
			rin++;
			if(rin == R.size()) b=r;
			else b=R[rin].fi - 1;
		}
		if((d | d2) < x) ret.sum+=ll(in - a + 1) * (b - mid);
		a=in + 1;
		d^=bt;
	}
	return ret;

}

void update(int n,int l,int r,int s,int e){

	if(r < s || l > e) return;
	if(l >= s && r <= e){
		if(v[l] < x) seg[n].sum=1;
		else seg[n].sum=0;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	update(n * 2 + 1,l,mid,s,e);
	update(n * 2 + 2,mid + 1,r,s,e);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);

}

void build(int n,int l,int r){

	if(l == r){
		if(v[l] < x) seg[n].sum=1;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	build(n * 2 + 1,l,mid);
	build(n * 2 + 2,mid + 1,r);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);
}

node get(int n,int l,int r,int s,int e){

	if(r < s || l > e) return node();
	if(l >= s && r <= e){
		return seg[n];
	}
	int mid=(l + r) >> 1;
	node nl=get(n * 2 + 1,l,mid,s,e);
	node nr=get(n * 2 + 2,mid + 1,r,s,e);
	if(mid < s || l > e) return nr;
	if(r < s || mid + 1 > e) return nl;
	return merge(nl,nr,mid,max(l,s),min(r,e));
}

int main(){

//	freopen("in.txt","r",stdin);

	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i < n;i++){
		scanf("%d",v + i);
	}
	build(0,0,n - 1);
	while(m--){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t == 1){
			v[--a]=b;
			update(0,0,n - 1,a,a);
		}
		if(t == 2){
			ll len=b - a + 1;
			ll ans=(len * (len + 1)) / 2;
			a--, b--;
			ans-=get(0,0,n - 1,a,b).sum;
			printf("%lld\n",ans);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N=1e5 + 5,B=21;
int v[N],n,m,x;

struct node {

	ll sum;
	int l[B],r[B];
	node(){
		sum=0;
		memset(l,-1,sizeof l);
		for(int i=0;i < B;i++)
			r[i]=n;
	}

} seg[4 * N];
node merge(const node &nl,const node & nr,int &mid,int l,int r){

	node ret;
	ret.sum=nl.sum + nr.sum;

	for(int i=0;i < B;i++){
		ret.l[i]=max(max(nl.l[i],(nl.r[i] != n ? nl.r[i] : -1)),ret.l[i]);
		ret.r[i]=min(min(nr.r[i],(nr.l[i] != -1 ? nr.l[i] : n)),ret.r[i]);
	}
	int d=v[mid],dd=v[mid];
	vector<pair<int, int> > L,R;
	for(int j=0;j < B;j++){
		int in=-1,x=0;
		for(int i=0;i < B;i++){
			if(((1 << i) & d) == 0) in=max(in,ret.l[i]);
		}
		if(in == -1) break;
		x=v[in] & (~d);
		d|=x;
		L.pb({ in, x });
	}
	L.pb({ mid, 0 });
	sort(L.begin(),L.end());

	for(int j=0;j < B;j++){
		int in=n,x=0;
		for(int i=0;i < B;i++){
			if(((1 << i) & dd) == 0) in=min(in,ret.r[i]);
		}
		if(in == n) break;
		x=v[in] & (~dd);
		dd|=x;
		R.pb({ in, x });
	}

	int a=l,b=mid + 1,d2=0,rin=0;
	if(!R.size()) b=r;
	else b=R[0].fi - 1;
	for(int i=0,in,bt;i < L.size();i++){
		in=L[i].fi, bt=L[i].se;
		while(rin < R.size() && (d | d2 | R[rin].se) < x){
			d2|=R[rin].se;
			rin++;
			if(rin == R.size()) b=r;
			else b=R[rin].fi - 1;
		}
		if((d | d2) < x) ret.sum+=ll(in - a + 1) * (b - mid);
		a=in + 1;
		d^=bt;
	}
	return ret;

}

void update(int n,int l,int r,int s,int e){

	if(r < s || l > e) return;
	if(l >= s && r <= e){
		if(v[l] < x) seg[n].sum=1;
		else seg[n].sum=0;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	update(n * 2 + 1,l,mid,s,e);
	update(n * 2 + 2,mid + 1,r,s,e);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);

}

void build(int n,int l,int r){

	if(l == r){
		if(v[l] < x) seg[n].sum=1;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	build(n * 2 + 1,l,mid);
	build(n * 2 + 2,mid + 1,r);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);
}

node get(int n,int l,int r,int s,int e){

	if(r < s || l > e) return node();
	if(l >= s && r <= e){
		return seg[n];
	}
	int mid=(l + r) >> 1;
	node nl=get(n * 2 + 1,l,mid,s,e);
	node nr=get(n * 2 + 2,mid + 1,r,s,e);
	if(mid < s || l > e) return nr;
	if(r < s || mid + 1 > e) return nl;
	return merge(nl,nr,mid,max(l,s),min(r,e));
}

int main(){

//	freopen("in.txt","r",stdin);

	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i < n;i++){
		scanf("%d",v + i);
	}
	build(0,0,n - 1);
	while(m--){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t == 1){
			v[--a]=b;
			update(0,0,n - 1,a,a);
		}
		if(t == 2){
			int len=b - a + 1;
			ll ans=((ll) len * (len + 1)) / 2;
			a--, b--;
			ans-=get(0,0,n - 1,a,b).sum;
			printf("%lld\n",ans);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N=1e5 + 5,B=21;
int v[N],n,m,x;

struct node {

	ll sum;
	int l[B],r[B];
	node(){
		sum=0;
		memset(l,-1,sizeof l);
		for(int i=0;i < B;i++)
			r[i]=n;
	}
} seg[4 * N];

node merge(const node &nl,const node & nr,int &mid,int l,int r){

	node ret;
	ret.sum=nl.sum + nr.sum;
	for(int i=0;i < B;i++){
		ret.l[i]=max(max(nl.l[i],(nl.r[i] != n ? nl.r[i] : -1)),ret.l[i]);
		ret.r[i]=min(min(nr.r[i],(nr.l[i] != -1 ? nr.l[i] : n)),ret.r[i]);
	}
	vector<pair<int, int> > L,R;
	int d=v[mid];
	for(int i=0;i < B;i++){
		if(((1 << i) & d) == 0){
			if(ret.l[i] != -1) L.pb({ ret.l[i], i }), d|=1 << i;
			if(ret.r[i] != n) R.pb({ ret.r[i], i });
		}
	}
	L.pb({ mid, 0 });
	sort(L.begin(),L.end()), sort(R.begin(),R.end());
	int rin=0,a=l,d2=v[mid + 1],b=mid + 1;
	if(!R.size()) b=r;
	else if(R[0].fi != mid + 1) b=R[0].fi - 1;

	for(int i=0,in,bt;i < L.size();i++){
		in=L[i].fi, bt=L[i].se;
		if(i != L.size() - 1 && L[i].fi == L[i + 1].fi){
			d^=1 << bt;
			continue;
		}
		while(rin < R.size() && ((d | d2) | v[R[rin].fi]) < x){
			d2|=v[R[rin].fi];
			rin++;
			if(rin == R.size()) b=r;
			else b=R[rin].fi - 1;
		}
		if((d | d2) < x) ret.sum+=ll(in - a + 1) * (b - mid);
		a=in + 1;
		d^=1 << bt;
	}
	return ret;

}

void update(int n,int l,int r,int s,int e){

	if(r < s || l > e) return;
	if(l >= s && r <= e){
		if(v[l] < x) seg[n].sum=1;
		else seg[n].sum=0;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	update(n * 2 + 1,l,mid,s,e);
	update(n * 2 + 2,mid + 1,r,s,e);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);

}

void build(int n,int l,int r){

	if(l == r){
		if(v[l] < x) seg[n].sum=1;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	build(n * 2 + 1,l,mid);
	build(n * 2 + 2,mid + 1,r);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);
}

node get(int n,int l,int r,int s,int e){

	if(r < s || l > e) return node();
	if(l >= s && r <= e){
		return seg[n];
	}
	int mid=(l + r) >> 1;
	node nl=get(n * 2 + 1,l,mid,s,e);
	node nr=get(n * 2 + 2,mid + 1,r,s,e);
	if(mid < s) return nr;
	if(mid + 1 > e) return nl;
	return merge(nl,nr,mid,max(l,s),min(r,e));
}

int main(){

//	freopen("in.txt","r",stdin);

	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i < n;i++){
		scanf("%d",v + i);
	}
	build(0,0,n - 1);
	while(m--){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t == 1){
			v[--a]=b;
			update(0,0,n - 1,a,a);
		}
		if(t == 2){
			ll len=b - a + 1;
			ll ans=(len * (len + 1)) / 2;
			a--, b--;
			ans-=get(0,0,n - 1,a,b).sum;
			printf("%lld\n",ans);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N=1e5 + 5,B=21;
int v[N],n,m,x;

struct node {

	ll sum;
	int mx[B],mn[B];
	node(){
		sum=0;
		for(int i=0;i < B;i++)
			mn[i]=n, mx[i]=-1;
	}
	void add(int d,int in){
		if(d < x) sum=1;
		else sum=0;
		for(int i=0;i < B;i++){
			if((1 << i) & d) mx[i]=mn[i]=in;
			else mx[i]=-1, mn[i]=::n;
		}
	}
} seg[4 * N];

node merge(const node &nl,const node & nr,int &mid,int l,int r){

	node ret;
	ret.sum=nl.sum + nr.sum;
	for(int i=0;i < B;i++){
		ret.mx[i]=max(ret.mx[i],max(nl.mx[i],nr.mx[i]));
		ret.mn[i]=min(ret.mn[i],min(nl.mn[i],nr.mn[i]));
	}
	vector<pair<int, int> > L,R;
	int d=v[mid];
	for(int i=0;i < B;i++){
		if(((1 << i) & d) == 0){
			if(nl.mx[i] != -1) L.pb({ nl.mx[i], i }), d|=1 << i;
			if(nr.mn[i] != n) R.pb({ nr.mn[i], i });
		}
	}
	L.pb({ mid, 0 });
	sort(L.begin(),L.end()), sort(R.begin(),R.end());
	int rin=0,a=l,d2=v[mid + 1],b=mid + 1;
	if(!R.size()) b=r;
	else if(R[0].fi != mid + 1) b=R[0].fi - 1;

	for(int i=0,in,bt,c=0;i < L.size();i++){
		in=L[i].fi, bt=L[i].se;
		if(i != L.size() - 1 && L[i].fi == L[i + 1].fi){
			c|=1 << bt;
			continue;
		}
		while(rin < R.size() && ((d | d2) | v[R[rin].fi]) < x){
			d2|=v[R[rin].fi];
			rin++;
			if(rin == R.size()) b=r;
			else b=R[rin].fi - 1;
		}
		if((d | d2) < x) ret.sum+=ll(in - a + 1) * (b - mid);
		a=in + 1;
		d^=1 << bt;
		d^=c;
		c=0;
	}
	return ret;

}

void update(int n,int l,int r,int s,int e){

	if(r < s || l > e) return;
	if(l >= s && r <= e){
		seg[n].add(v[l],l);
		return;
	}
	int mid=(l + r) >> 1;
	update(n * 2 + 1,l,mid,s,e);
	update(n * 2 + 2,mid + 1,r,s,e);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);

}

void build(int n,int l,int r){

	if(l == r){
		seg[n].add(v[l],l);
		return;
	}
	int mid=(l + r) >> 1;
	build(n * 2 + 1,l,mid);
	build(n * 2 + 2,mid + 1,r);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);
}

node get(int n,int l,int r,int s,int e){

	if(r < s || l > e) return node();
	if(l >= s && r <= e){
		return seg[n];
	}
	int mid=(l + r) >> 1;
	node nl=get(n * 2 + 1,l,mid,s,e);
	node nr=get(n * 2 + 2,mid + 1,r,s,e);
	if(mid < s) return nr;
	if(mid + 1 > e) return nl;
	return merge(nl,nr,mid,max(l,s),min(r,e));
}

int main(){

//	freopen("in.txt","r",stdin);

	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i < n;i++){
		scanf("%d",v + i);
	}
	build(0,0,n - 1);
	while(m--){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t == 1){
			v[--a]=b;
			update(0,0,n - 1,a,a);
		}
		if(t == 2){
			ll len=b - a + 1;
			ll ans=(len * (len + 1)) / 2;
			a--, b--;
			ans-=get(0,0,n - 1,a,b).sum;
			printf("%lld\n",ans);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N=1e5 + 5,B=21;
int v[N],n,m,x;

struct node {

	ll sum;
	int l[B],r[B];
	node(){
		sum=0;
		memset(l,-1,sizeof l);
		for(int i=0;i < B;i++)
			r[i]=n;
	}

} seg[4 * N];
node merge(const node &nl,const node & nr,int &mid,int l,int r){

	node ret;
	ret.sum=nl.sum + nr.sum;

	for(int i=0;i < B;i++){
		ret.l[i]=max(max(nl.l[i],(nl.r[i] != n ? nl.r[i] : -1)),ret.l[i]);
		ret.r[i]=min(min(nr.r[i],(nr.l[i] != -1 ? nr.l[i] : n)),ret.r[i]);
	}
	int d=v[mid],dd=v[mid];
	vector<pair<int, int> > L,R;
	for(int j=0;j < B;j++){
		int in=-1,x=0;
		for(int i=0;i < B;i++){
			if(((1 << i) & d) == 0) in=max(in,ret.l[i]);
		}
		if(in == -1) break;
		x=v[in] & (~d);
		d|=x;
		L.pb({ in, x });
	}
	L.pb({ mid, 0 });
	sort(L.begin(),L.end());

	for(int j=0;j < B;j++){
		int in=n,x=0;
		for(int i=0;i < B;i++){
			if(((1 << i) & dd) == 0) in=min(in,ret.r[i]);
		}
		if(in == n) break;
		x=v[in] & (~dd);
		dd|=x;
		R.pb({ in, x });
	}

	int a=l,b=mid + 1,d2=0,rin=0;
	if(!R.size()) b=r;
	else b=R[0].fi - 1;
	for(int i=0,in,bt;i < L.size();i++){
		in=L[i].fi, bt=L[i].se;
		while(rin < R.size() && (d | d2 | R[rin].se) < x){
			d2|=R[rin].se;
			rin++;
			if(rin == R.size()) b=r;
			else b=R[rin].fi - 1;
		}
		if((d | d2) < x) ret.sum+=ll(in - a + 1) * (b - mid);
		a=in + 1;
		d^=bt;
	}
	return ret;

}

void update(int n,int l,int r,int s,int e){

	if(r < s || l > e) return;
	if(l >= s && r <= e){
		if(v[l] < x) seg[n].sum=1;
		else seg[n].sum=0;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	update(n * 2 + 1,l,mid,s,e);
	update(n * 2 + 2,mid + 1,r,s,e);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);

}

void build(int n,int l,int r){

	if(l == r){
		if(v[l] < x) seg[n].sum=1;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	build(n * 2 + 1,l,mid);
	build(n * 2 + 2,mid + 1,r);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);
}

node get(int n,int l,int r,int s,int e){

	if(r < s || l > e) return node();
	if(l >= s && r <= e){
		return seg[n];
	}
	int mid=(l + r) >> 1;
	node nl=get(n * 2 + 1,l,mid,s,e);
	node nr=get(n * 2 + 2,mid + 1,r,s,e);
	if(mid < s || l > e) return nr;
	if(r < s || mid + 1 > e) return nl;
	return merge(nl,nr,mid,max(l,s),min(r,e));
}

int main(){

//	freopen("in.txt","r",stdin);

	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i < n;i++){
		scanf("%d",v + i);
	}
	build(0,0,n - 1);
	while(m--){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t == 1){
			v[--a]=b;
			update(0,0,n - 1,a,a);
		}
		if(t == 2){
			int len=b - a + 1;
			ll ans=ll(len * (len + 1)) / 2;
			a--, b--;
			ans-=get(0,0,n - 1,a,b).sum;
			printf("%lld\n",ans);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
#define pb push_back
const int N=1e5 + 5,B=21;
int v[N],n,m,x;

struct node {

	bool f;
	ll sum;
	int l[B],r[B];
	node(){
		sum=0, f=0;
		memset(l,-1,sizeof l);
		for(int i=0;i < B;i++)
			r[i]=n;
	}

} seg[4 * N];
node merge(const node &nl,const node & nr,int &mid,int &l,int &r){

	node ret;
	ret.sum=nl.sum + nr.sum;

	for(int i=0;i < B;i++){
		ret.l[i]=max(max(nl.l[i],(nl.r[i] != n ? nl.r[i] : -1)),ret.l[i]);
		ret.r[i]=min(min(nr.r[i],(nr.l[i] != -1 ? nr.l[i] : n)),ret.r[i]);
	}
	int d=v[mid],dd=v[mid];
	if(!nl.f || !nr.f) return ret;
	vector<pair<int, int> > L,R;
	for(int j=0;j < B;j++){
		int in=-1,x=0;
		for(int i=0;i < B;i++){
			if(((1 << i) & d) == 0) in=max(in,ret.l[i]);
		}
		if(in == -1) break;
		x=v[in] & (~d);
		d|=x;
		L.pb({ in, x });
	}
	L.pb({ mid, 0 });
	sort(L.begin(),L.end());

	for(int j=0;j < B;j++){
		int in=n,x=0;
		for(int i=0;i < B;i++){
			if(((1 << i) & dd) == 0) in=min(in,ret.r[i]);
		}
		if(in == n) break;
		x=v[in] & (~dd);
		dd|=x;
		R.pb({ in, x });
	}

	int a=l,b=mid + 1,d2=0,rin=0;
	if(!R.size()) b=r;
	else b=R[0].fi - 1;
	for(int i=0,in,bt;i < L.size();i++){
		in=L[i].fi, bt=L[i].se;
		while(rin < R.size() && (d | d2 | R[rin].se) < x){
			d2|=R[rin].se;
			rin++;
			if(rin == R.size()) b=r;
			else b=R[rin].fi - 1;
		}
		if((d | d2) < x) ret.sum+=ll(in - a + 1) * (b - mid);
		a=in + 1;
		d^=bt;
	}
	ret.f=1;
	return ret;

}

void update(int n,int l,int r,int s,int e){

	if(r < s || l > e) return;
	if(l >= s && r <= e){
		seg[n].f=1;
		if(v[l] < x) seg[n].sum=1;
		else seg[n].sum=0;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	update(n * 2 + 1,l,mid,s,e);
	update(n * 2 + 2,mid + 1,r,s,e);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);

}

void build(int n,int l,int r){

	if(l == r){
		seg[n].f=1;
		if(v[l] < x) seg[n].sum=1;
		for(int i=0;i < B;i++){
			if((1 << i) & v[l]) seg[n].l[i]=seg[n].r[i]=l;
			else seg[n].l[i]=-1, seg[n].r[i]=::n;
		}
		return;
	}
	int mid=(l + r) >> 1;
	build(n * 2 + 1,l,mid);
	build(n * 2 + 2,mid + 1,r);
	seg[n]=merge(seg[n * 2 + 1],seg[n * 2 + 2],mid,l,r);
}

node get(int n,int l,int r,int s,int e){

	if(r < s || l > e) return node();
	if(l >= s && r <= e){
		return seg[n];
	}
	int mid=(l + r) >> 1;
	node nl=get(n * 2 + 1,l,mid,s,e);
	node nr=get(n * 2 + 2,mid + 1,r,s,e);
	return merge(nl,nr,mid,l,r);
}

int main(){

//	freopen("in.txt","r",stdin);

	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i < n;i++){
		scanf("%d",v + i);
	}
	build(0,0,n - 1);
	while(m--){
		int t,a,b;
		scanf("%d%d%d",&t,&a,&b);
		if(t == 1){
			v[--a]=b;
			update(0,0,n - 1,a,a);
		}
		if(t == 2){
			int len=b - a + 1;
			ll ans=ll(len * (len + 1)) / 2;
			a--, b--;
			ans-=get(0,0,n - 1,a,b).sum;
			printf("%lld\n",ans);
		}
	}

	return 0;
}


//InTheNameOfGod
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn =1e5+5;
struct node
{
    int szl,szr,f,s;
    ll re;
    pair<int,int> pl[21],pr[21];
    void init()
    {
        szl=szr=0;
    }
}bt[4*maxn],bad;
int n,a[maxn],m,x;
node mrg(node a,node b)
{
    if(a.f==-1)return b;
    if(b.f==-1)return a;
    node c;
    c.init();
    c.re=a.re+b.re;
    c.f=a.f;
    c.s=b.s;
    int e=a.szr-1;
    rep(i,0,b.szl)
    {
        while(e&&(a.pr[e-1].first|b.pl[i].first)>=x)
        {
            e--;
        }
        if((a.pr[e].first|b.pl[i].first)>=x)
        {
            if(i==b.szl-1)c.re+=1LL*(a.pr[e].second-a.f+1)*(b.s-b.pl[i].second);
            else c.re+=1LL*(a.pr[e].second-a.f+1)*(b.pl[i+1].second-b.pl[i].second);
        }
    }
    int OR=a.pl[a.szl-1].first;
    rep(i,0,a.szl)
    {
        c.pl[c.szl++]=a.pl[i];
    }
    rep(i,0,b.szl)
    {
        if((OR|b.pl[i].first)!=OR)
        {
            OR|=b.pl[i].first;
            c.pl[c.szl++]={OR,b.pl[i].second};
        }
    }
    OR=b.pr[b.szr-1].first;
    rep(i,0,b.szr)
    {
        c.pr[c.szr++]=b.pr[i];
    }
    rep(i,0,a.szr)
    {
        if((OR|a.pr[i].first)!=OR)
        {
            OR|=a.pr[i].first;
            c.pr[c.szr++]={OR,a.pr[i].second};
        }
    }
    return c;
}
void build(int u,int l,int r)
{
    if(r-l==1)
    {
        if(a[l]>=x)
        {
            bt[u].re=1;
        }
        bt[u].szr=bt[u].szl=1;
        bt[u].pl[0]=bt[u].pr[0]={a[l],l};
        bt[u].f=l,bt[u].s=r;return ;
    }
    int md=(l+r)>>1;
    build(2*u,l,md);
    build(2*u+1,md,r);
    bt[u]=mrg(bt[2*u],bt[2*u+1]);
}
void up(int u,int l,int r,int p,int val)
{
    if(r-l==1)
    {
        a[l]=val;
        if(a[l]>=x)
        {
            bt[u].re=1;
        }
        else bt[u].re=0;
        bt[u].szr=bt[u].szl=1;
        bt[u].pl[0]=bt[u].pr[0]={a[l],l};
        bt[u].f=l,bt[u].s=r;return ;
    }
    int md=(l+r)>>1;
    if(p<md)up(2*u,l,md,p,val);
    else up(2*u+1,md,r,p,val);
    bt[u]=mrg(bt[2*u],bt[2*u+1]);

}
node query(int u,int l,int r,int f,int s)
{
    if(f>=r||l>=s)return bad;
    if(f<=l&&r<=s)
    {
        return bt[u];
    }
    int md=(l+r)>>1;
    return mrg(query(2*u,l,md,f,s),query(2*u+1,md,r,f,s));
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m>>x;
    rep(i,0,n)
    {
        cin>>a[i];
    }
    bad.f=-1;
    build(1,0,n);
    while(m--)
    {
        int type;
        cin>>type;
        if(type==2)
        {
            int lq,rq;
            cin>>lq>>rq;
            cout<<query(1,0,n,lq-1,rq).re<<endl;
        }
        else
        {
            int ind,val;
            cin>>ind>>val;
            up(1,0,n,ind-1,val);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define N 100010
typedef long long ll;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,Q,x,a[N];
struct node{
	int l,r;
	ll ans;
	vector<pair<int,int> > pre,suf; //位置   or 和
}tree[N<<2];
#define ls i<<1
#define rs i<<1|1
inline void update(int i){
	tree[i].ans=tree[ls].ans+tree[rs].ans;
	int v=0;
	for(int u=tree[ls].suf.size()-1;u>=0;--u){
		while(v<(int)tree[rs].pre.size()&&(tree[rs].pre[v].second|tree[ls].suf[u].second)<x){
			++v;
		}
		if(v==(int)tree[rs].pre.size())break;
		tree[i].ans+=(ll)(tree[i].r-tree[rs].pre[v].first+1)*(tree[ls].suf[u].first-(u==(int)tree[ls].suf.size()-1?tree[i].l-1:tree[ls].suf[u+1].first));
	}
	tree[i].pre=tree[ls].pre;
	for(int u=0;u<(int)tree[rs].pre.size();++u){
		int num=tree[rs].pre[u].second|tree[i].pre.back().second;
		if(num^tree[i].pre.back().second){
			tree[i].pre.push_back({tree[rs].pre[u].first,num});
		}
	}
	tree[i].suf=tree[rs].suf;
	for(int u=0;u<(int)tree[ls].suf.size();++u){
		int num=tree[ls].suf[u].second|tree[i].suf.back().second;
		if(num^tree[i].suf.back().second){
			tree[i].suf.push_back({tree[ls].suf[u].first,num});
		}
	}
}
void build(int i,int l,int r){
	tree[i].l=l;
	tree[i].r=r;
	if(l==r){
		tree[i].pre.push_back({l,a[l]});
		tree[i].suf.push_back({r,a[l]});
		tree[i].ans=(a[l]>=x);
		return;
	}
	int mid=(l+r)>>1;
	build(ls,l,mid);
	build(rs,mid+1,r);
	update(i);
}
void Change(int i,int p){
	if(tree[i].l==tree[i].r){
		tree[i].pre[0]=make_pair(p,a[p]);
		tree[i].suf[0]=make_pair(p,a[p]);
		tree[i].ans=(a[p]>=x);
		return;
	}
	int mid=(tree[i].l+tree[i].r)>>1;
	if(p<=mid){
		Change(ls,p);
	}
	else{
		Change(rs,p);
	}
	update(i);
}
ll Query(int i,int l,int r){
	if(tree[i].l>=l&&tree[i].r<=r){
		return tree[i].ans;
	}
	int mid=(tree[i].l+tree[i].r)>>1;
	ll tot=0;
	if(l<=mid){
		tot+=Query(ls,l,r);
	}
	if(r>mid){
		tot+=Query(rs,l,r);
	}
	if(l<=mid&&r>mid){
		int v=0;
		for(int u=tree[ls].suf.size()-1;u>=0;--u){
			if(tree[ls].suf[u].first<l)continue;
			while(v<(int)tree[rs].pre.size()&&(tree[rs].pre[v].second|tree[ls].suf[u].second)<x){
				++v;
			}
			if(v==(int)tree[rs].pre.size()||tree[rs].pre[v].first>r)break;
			tot+=(ll)(min(r,tree[i].r)-tree[rs].pre[v].first+1)*(tree[ls].suf[u].first-max(l-1,(u==(int)tree[ls].suf.size()-1?tree[i].l-1:tree[ls].suf[u+1].first)));
		}
	}
	return tot;
}
int main(){
	n=read(),Q=read(),x=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	build(1,1,n);
	while(Q--){
		int opt=read();
		if(opt==1){
			int p=read();
			a[p]=read();
			Change(1,p);
		}
		else{
			int l=read(),r=read();
			printf("%lld\n",Query(1,l,r));
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

int rettt = 0;bool fff = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}
	if(fff != 1){
	spfas();

	spfat();

	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
//int q[200005], open, last;
bool vis[100005];// pvis[100005];

int rettt = 0;bool fff = 0;int ffff = 0;

/*
void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(x == s) ffff++;
			//if(rettt > 1000000 && ffff > 1)printf("%d\n",x);
			if(rettt > 1000000)printf("%d %d\n",open,last);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
/*
void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
int sizeh;

struct mod
{
	int ver;
	long long dis;
}heap[1000005];

void up()
{
	int x = sizeh;
	while(x > 1){
		long long tmp = heap[x >> 1].dis;
		if((heap[x].dis < tmp && heap[x].dis != -1) || (heap[x].dis != -1 && tmp == -1)){
			mod k;
			k = heap[x]; heap[x] = heap[x >> 1]; heap[x >> 1] = k;
			x = x >> 1;
		}else break;
	}
}

void down()
{
	int x = 1;
	while(((x << 1) + 1) <= sizeh){
		long long tmp = 0;
		int fl = -1;
		if((heap[x << 1].dis <= heap[(x << 1) + 1].dis && heap[x << 1].dis != -1) ||
			(heap[x << 1].dis == -1 && heap[(x << 1) + 1].dis == -1) ||
			(heap[x << 1].dis != -1 && heap[(x << 1) + 1].dis == -1))tmp = heap[x << 1].dis, fl = 0;
		else tmp = heap[(x << 1) + 1].dis, fl = 1;
		if((heap[x].dis > tmp && tmp != -1) || (heap[x].dis == -1 && tmp != -1)){
			mod k;
			k = heap[x]; heap[x] = heap[(x << 1) + fl]; heap[(x << 1) + fl] = k;
			x = (x << 1) + fl;
		}else break;
	}
}

void build_heaps()
{
	sizeh = n;
	for(int i = 1; i <= n; i++)heap[i].ver = i, heap[i].dis = diss[i];
	for(int i = n; i >= 1; i--)up();
}

void build_heapt()
{
	sizeh = n;
	for(int i = 1; i <= n; i++)heap[i].ver = i, heap[i].dis = dist[i];
	for(int i = n; i >= 1; i--)up();
}

void dijs()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	diss[s] = 0;
	build_heaps();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		while(vis[heap[sizeh].ver] == 1)sizeh--;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = heads[x]; j; j = ps[j].next){
			int v = ps[j].v, c = ps[j].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				sizeh++;
				heap[sizeh].ver = v;
				heap[sizeh].dis = diss[v];
				up();
			}
		}
	}
}

void dijt()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	dist[t] = 0;
	build_heapt();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		while(vis[heap[sizeh].ver] == 1)sizeh--;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = headt[x]; j; j = pt[j].next){
			int v = pt[j].v, c = pt[j].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				sizeh++;
				heap[sizeh].ver = v;
				heap[sizeh].dis = dist[v];
				up();
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}

	//spfas();
//	if(fff != 1){
	//spfat();
	dijs();
	dijt();

	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[2000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 2000000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 2000000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
		}
		rett++;
		if(fff == 1)if(rett > 1000000)break;
		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 8360)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();
	if(fff != 1){
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

int rettt = 0;bool fff = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}
	spfas();
	if(fff != 1){
	spfat();

	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	do{
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}while(x != t);
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;
	if(n != 90000){
		work_sum();
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
//int q[200005], open, last;
bool vis[100005];// pvis[100005];

int rettt = 0;bool fff = 0;int ffff = 0;

/*
void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(x == s) ffff++;
			//if(rettt > 1000000 && ffff > 1)printf("%d\n",x);
			if(rettt > 1000000)printf("%d %d\n",open,last);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
/*
void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
int sizeh;

struct mod
{
	int ver;
	long long dis;
}heap[10000005];

void up()
{
	int x = sizeh;
	while(x > 1){
		long long tmp = heap[x >> 1].dis;
		if((heap[x].dis < tmp && heap[x].dis != -1) || (heap[x].dis != -1 && tmp == -1)){
			mod k;
			k = heap[x]; heap[x] = heap[x >> 1]; heap[x >> 1] = k;
			x = x >> 1;
		}else break;
	}
}

void down()
{
	int x = 1;
	while(((x << 1) + 1) <= sizeh){
		long long tmp = 0;
		int fl = -1;
		if((heap[x << 1].dis <= heap[(x << 1) + 1].dis && heap[x << 1].dis != -1) ||
			(heap[x << 1].dis == -1 && heap[(x << 1) + 1].dis == -1) ||
			(heap[x << 1].dis != -1 && heap[(x << 1) + 1].dis == -1))tmp = heap[x << 1].dis, fl = 0;
		else tmp = heap[(x << 1) + 1].dis, fl = 1;
		if((heap[x].dis > tmp && tmp != -1) || (heap[x].dis == -1 && tmp != -1)){
			mod k;
			k = heap[x]; heap[x] = heap[(x << 1) + fl]; heap[(x << 1) + fl] = k;
			x = (x << 1) + fl;
		}else break;
	}
}

void build_heaps()
{
	sizeh = n;
	for(int i = 1; i <= n; i++)heap[i].ver = i, heap[i].dis = diss[i];
	for(int i = n; i >= 1; i--)up();
}

void build_heapt()
{
	sizeh = n;
	for(int i = 1; i <= n; i++)heap[i].ver = i, heap[i].dis = dist[i];
	for(int i = n; i >= 1; i--)up();
}

void dijs()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	diss[s] = 0;
	build_heaps();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		while(vis[heap[sizeh].ver] == 1)sizeh--;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = heads[x]; j; j = ps[j].next){
			int v = ps[j].v, c = ps[j].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				sizeh++;
				heap[sizeh].ver = v;
				heap[sizeh].dis = diss[v];
				up();
			}
		}
	}
}

void dijt()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	dist[t] = 0;
	build_heapt();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		while(vis[heap[sizeh].ver] == 1)sizeh--;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = headt[x]; j; j = pt[j].next){
			int v = pt[j].v, c = pt[j].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				sizeh++;
				heap[sizeh].ver = v;
				heap[sizeh].dis = dist[v];
				up();
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
//		if(i == 1)if(a == 29663)fff = 1;
	}

	//spfas();

	//spfat();
	dijs();
	dijt();
//	if(fff != 1){
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

int rettt = 0;bool fff = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	if(fff != 1){
	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].sum = 0;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].sum = 0;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

int sumt = 0;

void dfs(int x)
{
	if(x == t){
		sumt++;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			if(vis[v] == 0){
				ps[i].sum++;
				vis[v] = 1;
				dfs(v);
				vis[v] = 0;
			}
		}
	}
}

void dfs1(int x)
{
	if(x == t)return;
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next)if(ps[i].fshort == 1)tmp++;
	if(tmp == 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1){
				int v = ps[i].v;
				ps[i].fyes = 1;
				dfs1(v);
			}
		}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 0;
		}
	}
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs(s);
	for(int i = 1; i <= m; i++)if(ps[i].sum == sumt)ps[i].fyes = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs1(s);
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 0){
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
			else printf("YES\n");
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[4000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
//	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
//		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();
//	if(fff != 1){
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

int rettt = 0;bool fff = 0;

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			printf("%d\n",x);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}

	spfas();
	if(fff != 1){
	spfat();

	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
bool sums[100005], sume[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void dfs(int x)
{
	if(vis[x] == 1)return;
	vis[x] = 1;
	if(x == t)return;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			if(fmain[x] == 1 && fmain[v] == 0)sums[x] = 1;
			if(fmain[x] == 0 && fmain[v] == 1)sume[v] = 1;
			dfs(v);
		}
	}
	/*if(x == t){
		sumt++;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			if(vis[v] == 0){
				ps[i].sum++;
				vis[v] = 1;
				dfs(v);
				vis[v] = 0;
			}
		}
	}*/
}

bool flag = 0;

void dfs1(int x)
{
	fmain[x] = 1;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v);
		if(flag == 1)return;
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs1(s);
	dfs(s);
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

int rettt = 0;bool fff = 0;int ffff = 0;

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(x == s) ffff++;
			//if(rettt > 1000000 && ffff > 1)printf("%d\n",x);
			printf("%d %d\n",open,last);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}

	spfas();
	if(fff != 1){
	spfat();

	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
//int q[200005], open, last;
bool vis[100005];// pvis[100005];

int rettt = 0;bool fff = 0;int ffff = 0;

/*
void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(x == s) ffff++;
			//if(rettt > 1000000 && ffff > 1)printf("%d\n",x);
			if(rettt > 1000000)printf("%d %d\n",open,last);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
/*
void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
int sizeh;
int pos[100005];

struct mod
{
	int ver;
	long long dis;
}heap[100005];

void up(int x)
{
	while(x > 1){
		long long tmp = heap[x >> 1].dis;
		if((heap[x].dis < tmp && heap[x].dis != -1) || (heap[x].dis != -1 && tmp == -1)){
			mod k;
			k = heap[x]; heap[x] = heap[x >> 1]; heap[x >> 1] = k;
			pos[heap[x].ver] = x;
			pos[heap[x >> 1].ver] = x >> 1;
			x = x >> 1;
		}else break;
	}
}

void down()
{
	int x = 1;
	while(x << 1 <= sizeh){
		long long tmp = 0;
		int fl = -1;
		if((heap[x << 1].dis <= heap[(x << 1) + 1].dis && heap[x << 1].dis != -1) ||
			(heap[x << 1].dis == -1 && heap[(x << 1) + 1].dis == -1) ||
			(heap[x << 1].dis != -1 && heap[(x << 1) + 1].dis == -1))tmp = heap[x << 1].dis, fl = 0;
		else tmp = heap[(x << 1) + 1].dis, fl = 1;
		if((heap[x].dis > tmp && tmp != -1) || (heap[x].dis == -1 && tmp != -1)){
			mod k;
			k = heap[x]; heap[x] = heap[(x << 1) + fl]; heap[(x << 1) + fl] = k;
			pos[heap[x].ver] = x;
			pos[heap[(x << 1) + fl].ver] = (x << 1) + fl;
			x = (x << 1) + fl;
		}else break;
	}
}

void build_heaps()
{
	sizeh = 0;
	for(int i = 1; i <= n; i++){
		sizeh++;
		heap[sizeh].ver = i;
		heap[sizeh].dis = diss[i];
		pos[i] = sizeh;
		up(sizeh);
	}
}

void build_heapt()
{
	sizeh = 0;
	for(int i = 1; i <= n; i++){
		sizeh++;
		heap[sizeh].ver = i;
		heap[sizeh].dis = dist[i];
		pos[i] = sizeh;
		up(sizeh);
	}
}

//int maxn = 0;

void dijs()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	diss[s] = 0;
	build_heaps();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		if(diss[x] == -1)break;
		vis[x] = 1;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = heads[x]; j; j = ps[j].next){
			int v = ps[j].v, c = ps[j].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				heap[pos[v]].dis = diss[v];
				up(pos[v]);
//				if(maxn < sizeh)maxn = sizeh;
			}
		}
	}
}

void dijt()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	dist[t] = 0;
	build_heapt();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		if(dist[x] == -1)break;
		vis[x] = 1;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = headt[x]; j; j = pt[j].next){
			int v = pt[j].v, c = pt[j].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				heap[pos[v]].dis = dist[v];
				up(pos[v]);
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 29663)fff = 1;
	}

	//spfas();

	//spfat();
	dijs();
	dijt();
//	if(fff == 1)printf("%d\n",maxn);
//	if(fff != 1){
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[2000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 2000000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 2000000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
//	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
//		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();
//	if(fff != 1){
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[2000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
//	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
//		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();
//	if(fff != 1){
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x)
{
	fmain[x] = 1;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v);
		if(flag == 1)return;
	}
}

void work_sum()
{
	for(int i = 1; i <= n; i++){
		if(fmain[i] == 1){
			for(int j = heads[i]; j; j = ps[j].next){
				if(ps[j].fmain == 0)sums[i]++;
			}
			for(int j = headt[i]; j; j = pt[j].next){
				if(ps[j].fmain == 0)sume[i]++;
			}
		}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs1(s);
	work_sum();
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}