#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 10, INF = 0x3f3f3f3f3f3f3f, MOD = 19491001,
                MOD2 = 19260817;
long long N, M, S, T, dis[2][MAXN], minn, ct = -1, head[MAXN], cnt[2][2][MAXN],
                                          vis[MAXN];
struct edge {
  long long nt, to, v;
} E[MAXN];
struct ed {
  long long x, y, v;
  ed() {}
  ed(long long _x, long long _y, long long _v) : x(_x), y(_y), v(_v) {}
} e[MAXN];
struct heap {
  long long val, pos;
  heap() {}
  heap(long long _val, long long _pos) : val(_val), pos(_pos) {}
  friend bool operator<(heap a, heap b) { return a.val > b.val; }
};
void add(long long, long long, long long);
void dijk(long long, long long);
int main() {
  memset(head, -1, sizeof(head));
  scanf("%lld%lld%lld%lld", &N, &M, &S, &T);
  for (long long i = 1, x, y, v; i <= M; i++) {
    scanf("%lld%lld%lld", &x, &y, &v);
    add(x, y, v);
    e[i] = ed(x, y, v);
  }
  dijk(0, S);
  memset(head, -1, sizeof(head));
  for (long long i = 1; i <= M; i++) add(e[i].y, e[i].x, e[i].v);
  dijk(1, T);
  minn = dis[0][T];
  for (long long i = 1; i <= M; i++) {
    long long x = e[i].x, y = e[i].y;
    long long tem = dis[0][x] + dis[1][y] + e[i].v;
    if (dis[0][x] + dis[1][y] > INF)
      puts("NO");
    else if (tem == minn) {
      if (cnt[0][0][T] == cnt[0][0][x] * cnt[1][0][y] % MOD &&
          cnt[0][1][T] == cnt[0][1][x] * cnt[1][1][y] % MOD2)
        puts("YES");
      else {
        if (e[i].v == 1)
          puts("NO");
        else
          printf("CAN 1\n");
      }
    } else {
      long long del = tem - minn + 1;
      if (del < e[i].v)
        printf("CAN %lld\n", del);
      else
        puts("NO");
    }
  }
  return 0;
}
void add(long long x, long long y, long long v) {
  ct++;
  E[ct].nt = head[x];
  head[x] = ct;
  E[ct].to = y;
  E[ct].v = v;
}
void dijk(long long id, long long n) {
  memset(dis[id], 0x3f, sizeof(dis[id]));
  memset(vis, 0, sizeof(vis));
  dis[id][n] = 0;
  cnt[id][0][n] = cnt[id][1][n] = 1;
  priority_queue<heap> q;
  q.push(heap(dis[id][n], n));
  while (!q.empty()) {
    heap nt = q.top();
    q.pop();
    if (dis[id][nt.pos] < nt.val || vis[nt.pos]) continue;
    vis[nt.pos] = 1;
    for (long long i = head[nt.pos]; ~i; i = E[i].nt) {
      long long v = E[i].to;
      if (dis[id][v] > dis[id][nt.pos] + E[i].v) {
        dis[id][v] = dis[id][nt.pos] + E[i].v;
        q.push(heap(dis[id][v], v));
        cnt[id][0][v] = cnt[id][0][nt.pos] % MOD;
        cnt[id][1][v] = cnt[id][1][nt.pos] % MOD2;
      } else if (dis[id][v] == dis[id][nt.pos] + E[i].v) {
        dis[id][v] = dis[id][nt.pos] + E[i].v;
        (cnt[id][0][v] += cnt[id][0][nt.pos]) %= MOD;
        (cnt[id][1][v] += cnt[id][1][nt.pos]) %= MOD2;
        if (!vis[v]) q.push(heap(dis[id][v], v));
      }
    }
  }
}
