#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 1e5;
struct _seg {
  ll l, r, i;
};
bool operator<(const _seg& a, const _seg& b) {
  if (a.l != b.l) return a.l < b.l;
  return a.r < b.r;
}
struct _e {
  int a, b, w;
};
struct _d {
  int v;
  ll w;
};
bool operator<(const _d& a, const _d& b) { return a.w > b.w; }
priority_queue<_d> pq;
void dijkstra(int& s, vector<vector<_d>>& adj, ll dist[MAX_N]) {
  dist[s] = 0;
  pq.push(_d{s, 0});
  while (!pq.empty()) {
    _d u = pq.top();
    pq.pop();
    if (dist[u.v] < u.w) continue;
    for (_d& e : adj[u.v])
      if (dist[e.v] > dist[u.v] + e.w) {
        dist[e.v] = dist[u.v] + e.w;
        pq.push(_d{e.v, dist[e.v]});
      }
  }
}
int main() {
  int n, m, s, t, a, b, w, i, idx;
  vector<int> ans;
  ll l, r, tmp;
  vector<_seg> seg;
  vector<_e> edges;
  vector<vector<_d>> adj, radj;
  ll dist[MAX_N], rdist[MAX_N];
  scanf("%d%d%d%d", &n, &m, &s, &t);
  adj.resize(n), radj.resize(n);
  ans.resize(m, 0);
  s--, t--;
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &w);
    a--, b--;
    edges.push_back(_e{a, b, w});
    adj[a].push_back(_d{b, w});
    radj[b].push_back(_d{a, w});
  }
  memset(dist, 0x3F, sizeof dist);
  memset(rdist, 0x3F, sizeof rdist);
  dijkstra(s, adj, dist);
  dijkstra(t, radj, rdist);
  for (i = 0; i < m; i++) {
    a = edges[i].a, b = edges[i].b, w = edges[i].w;
    if (dist[a] + rdist[b] + w == dist[t])
      seg.push_back(_seg{dist[a], dist[b], i});
    else
      ans[i] = -1;
  }
  sort(seg.begin(), seg.end());
  l = seg[0].l, r = seg[0].r, idx = seg[0].i;
  for (i = 1; i < (int)seg.size(); i++) {
    if (r <= seg[i].l)
      l = seg[i].l, r = seg[i].r, idx = seg[i].i;
    else {
      ans[seg[i].i] = ans[idx] = -1;
      r = r > seg[i].r ? r : seg[i].r;
    }
  }
  for (i = 0; i < m; i++) {
    if (ans[i] != 0) {
      a = edges[i].a, b = edges[i].b, w = edges[i].w;
      tmp = dist[t] - dist[a] - rdist[b] - w - 1;
      tmp = -tmp;
      if (w > tmp)
        printf("CAN %lld\n", tmp);
      else
        puts("NO");
    } else
      puts("YES");
  }
  return 0;
}
