#include <bits/stdc++.h>
using namespace std;
const long long MXN = 3e3 + 10;
const long long MXM = (1LL << 18) + 10;
const long long MX5 = 2e5 + 10;
const long long MX6 = 1e6 + 10;
const long long LOG = 20;
const long long INF = 8e18;
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}
long long bmm(long long a, long long b) {
  return (a % b == 0 ? b : bmm(b, a % b));
}
string base2(long long n) {
  string a = "";
  while (n >= 2) {
    a += (char)(n % 2 + '0');
    n /= 2;
  }
  a += (char)(n + '0');
  reverse((a).begin(), (a).end());
  return a;
}
long long n, m, s, t;
long long dis[2][MX5], par[2][MX5], dist[MX5];
vector<long long> G[2][MX5], Gp[MX5];
vector<pair<pair<long long, long long>, long long>> E;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    pq;
bool vis[MX5], ANS[MX5];
map<pair<pair<long long, long long>, long long>, long long> mp;
map<pair<long long, long long>, long long> wei;
inline void Dijkstra(long long Start, long long ind) {
  fill(dis[ind], dis[ind] + MX5, INF);
  fill(vis, vis + MX5, 0);
  dis[ind][Start] = 0;
  pq.push({0, Start});
  while (!pq.empty()) {
    long long u = pq.top().second, cost = pq.top().first;
    pq.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (auto id : G[ind][u]) {
      long long v = (E[id].first.first == u ? E[id].first.second
                                            : E[id].first.first),
                w = E[id].second;
      if (!vis[v] && cost + w < dis[ind][v]) {
        dis[ind][v] = cost + w;
        pq.push({dis[ind][v], v});
        par[ind][v] = id;
      }
    }
  }
  return;
}
long long DFS(long long u, long long par) {
  long long Min = INF;
  vis[u] = 1;
  for (auto id : Gp[u]) {
    long long v = (E[id].first.first == u ? E[id].first.second
                                          : E[id].first.first),
              w = E[id].second;
    if (v == par) continue;
    if (!vis[v]) {
      dist[v] = dist[u] + 1;
      long long now = DFS(v, u);
      ANS[id] = (now < dist[v] ? 0 : 1);
      Min = min(Min, now);
    } else {
      Min = min(Min, dist[v]);
    }
  }
  return Min;
}
int main() {
  cin >> n >> m >> s >> t;
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    G[0][u].push_back(i);
    G[1][v].push_back(i);
    E.push_back({{u, v}, w});
    mp[{{u, v}, w}]++;
    if (wei.find({u, v}) != wei.end())
      wei[{u, v}] = min(wei[{u, v}], w);
    else
      wei[{u, v}] = w;
  }
  Dijkstra(s, 0);
  Dijkstra(t, 1);
  for (int i = 0; i < m; i++) {
    long long u = E[i].first.first, v = E[i].first.second, w = E[i].second;
    if (dis[0][u] + w + dis[1][v] == dis[0][t]) {
      Gp[u].push_back(i);
      Gp[v].push_back(i);
    }
  }
  fill(vis, vis + MX5, 0);
  DFS(s, -1);
  for (int i = 0; i < m; i++) {
    long long u = E[i].first.first, v = E[i].first.second, w = E[i].second;
    if (dis[0][u] == INF) {
      cout << "NO" << '\n';
      continue;
    }
    if (dis[0][u] + w + dis[1][v] > dis[0][t]) {
      long long ans = dis[0][t] - 1 - dis[0][u] - dis[1][v];
      if (ans < 1) {
        cout << "NO" << '\n';
      } else {
        cout << "CAN " << w - ans << '\n';
      }
    } else {
      if (ANS[i] && mp[{{u, v}, w}] == 1 && wei[{u, v}] == w) {
        cout << "YES" << '\n';
      } else {
        long long ans = dis[0][t] - 1 - dis[0][u] - dis[1][v];
        if (ans < 1) {
          cout << "NO" << '\n';
        } else {
          cout << "CAN " << w - ans << '\n';
        }
      }
    }
  }
  return 0;
}
