#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long inf = 1e18 + 10;
long long dis[N], sid[N], mark[N], h[N], dp[N], c[N];
pair<pair<long long, long long>, long long> E[N];
vector<pair<long long, long long> > adj[N], jda[N], g[N];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    pq;
void dfs(long long v, long long id) {
  mark[v] = 1;
  dp[v] = inf;
  for (pair<long long, long long> e : g[v]) {
    long long u = e.first, ind = e.second;
    if (ind == id) continue;
    if (mark[u]) {
      dp[v] = min(dp[v], h[u]);
    } else {
      h[u] = h[v] + 1;
      dfs(u, ind);
      dp[v] = min(dp[v], dp[u]);
      if (h[v] < dp[u]) c[ind] = 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, s, t;
  cin >> n >> m >> s >> t;
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    jda[v].push_back({u, w});
    E[i] = {{u, v}, w};
  }
  fill(dis, dis + N, inf);
  dis[s] = 0;
  pq.push({0, s});
  while (!pq.empty()) {
    long long d = pq.top().first, v = pq.top().second;
    pq.pop();
    if (d != dis[v]) continue;
    for (pair<long long, long long> e : adj[v]) {
      long long u = e.first, w = e.second;
      if (d + w < dis[u]) {
        dis[u] = d + w;
        pq.push({d + w, u});
      }
    }
  }
  fill(sid, sid + N, inf);
  sid[t] = 0;
  pq.push({0, t});
  while (!pq.empty()) {
    long long d = pq.top().first, v = pq.top().second;
    pq.pop();
    if (d != sid[v]) continue;
    for (pair<long long, long long> e : jda[v]) {
      long long u = e.first, w = e.second;
      if (d + w < sid[u]) {
        sid[u] = d + w;
        pq.push({d + w, u});
      }
    }
  }
  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[u] + w + sid[v] == dis[t]) {
      g[u].push_back({v, i});
      g[v].push_back({u, i});
    }
  }
  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[u] + w + sid[v] == dis[t]) {
      if (c[i])
        cout << "YES\n";
      else if (1 < w)
        cout << "CAN" << ' ' << 1 << '\n';
      else
        cout << "NO\n";
    } else {
      long long cst = dis[u] + w + sid[v];
      long long dif = cst - dis[t] + 1;
      if (dif < w)
        cout << "CAN" << ' ' << dif << '\n';
      else
        cout << "NO\n";
    }
  }
  return 0;
}
