#include <bits/stdc++.h>
using namespace std;
struct edg {
  int v, w;
  edg() { v = w = 0; }
  edg(const int _v, const int _w) {
    v = _v;
    w = _w;
  }
};
int n, m, second, T;
int hei[100005];
char ans[100005];
bool vis[2][100005];
int64_t tar_dist;
int64_t dist[2][100005];
vector<edg> adj[3][100005];
vector<array<int, 3>> edges;
const int64_t inf = INT64_MAX >> 6;
inline void dijkstra(const int t, const int st) {
  fill(dist[t], dist[t] + n + 3, inf);
  dist[t][st] = 0;
  priority_queue<pair<int64_t, int64_t>> pq;
  pq.push({0, st});
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    int v = p.second;
    if (vis[t][v]) {
      continue;
    }
    vis[t][v] = true;
    int64_t d = dist[t][v];
    for (auto x : adj[t][v]) {
      int64_t rd = d + int64_t(x.w);
      if (rd < dist[t][x.v]) {
        dist[t][x.v] = rd;
        pq.push({-rd, x.v});
      }
    }
  }
}
int dfs1(int st, int pr, int h, int enm) {
  if (hei[st]) {
    return hei[st];
  }
  hei[st] = h;
  int mnh = h;
  for (auto x : adj[2][st]) {
    if (x.v == pr && x.w == enm) {
      continue;
    }
    mnh = min(mnh, dfs1(x.v, st, h + 1, x.w));
  }
  if (mnh == h) {
    ans[enm] = 'M';
  }
  return mnh;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &second, &T);
  for (int i = 1; i <= m; i++) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    adj[0][a].push_back(edg(b, w));
    adj[1][b].push_back(edg(a, w));
    edges.push_back(array<int, 3>{a, b, w});
  }
  dijkstra(0, second);
  dijkstra(1, T);
  tar_dist = dist[0][T];
  assert(tar_dist == dist[1][second]);
  if (tar_dist >= inf) {
    for (int i = 1; i <= m; i++) {
      puts("NO");
    }
    return 0;
  }
  for (int i = 0; i < m; i++) {
    const auto &e = edges[i];
    int64_t d = dist[0][e[0]] + dist[1][e[1]] + e[2];
    if (d == tar_dist) {
      adj[2][e[0]].push_back(edg(e[1], i));
      adj[2][e[1]].push_back(edg(e[0], i));
    }
  }
  dfs1(second, 0, 1, 100005 - 1);
  for (int i = 0; i < m; i++) {
    if (ans[i] == 'M') {
      puts("YES");
      continue;
    }
    const auto &e = edges[i];
    int64_t d = dist[0][e[0]] + dist[1][e[1]] + e[2];
    if (d >= inf) {
      puts("NO");
      continue;
    }
    int64_t delta = d - tar_dist + 1;
    if (delta < int64_t(e[2])) {
      printf("CAN %lld\n", delta);
    } else {
      puts("NO");
    }
  }
}
