#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long a, long long b, long long m) {
  if (b == 0LL) return 1LL;
  if (b == 1LL) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1LL) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
const long long N = 100100;
vector<long long> g[N], gr[N], dag[N];
const long long inf = 1e18;
struct edge {
  long long a, b;
  long long c;
  edge() {}
  edge(long long _a, long long _b, long long _c) {
    a = _a;
    b = _b;
    c = _c;
  }
} e[N];
long long nxt(long long id, long long from) { return e[id].a ^ e[id].b ^ from; }
long long n;
long long is_brigde[N];
long long vis2[N];
long long tin[N];
long long t = 1;
long long dfs2(long long v, long long p = -1) {
  vis2[v] = 1;
  tin[v] = t++;
  long long low = tin[v];
  for (long long x : dag[v]) {
    long long to = nxt(x, v);
    if (!vis2[to])
      low = min(low, dfs2(to, x));
    else if (x != p)
      low = min(low, tin[to]);
  }
  if (low == tin[v] and p != -1) is_brigde[p] = true;
  return low;
}
void DJ(vector<long long>& d, long long S, long long f = 0) {
  d.resize(n + 1);
  vector<long long> vis(n + 1), pai(n + 1);
  for (long long i = 1; i <= n; i++) {
    vis[i] = 0;
    d[i] = inf;
  }
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  pq.push(pair<long long, long long>(0, S));
  d[S] = 0;
  vis[S] = 1;
  pai[S] = -1;
  while (!pq.empty()) {
    long long cur = pq.top().second;
    pq.pop();
    if (f == -1) {
      for (auto ar : gr[cur]) {
        long long to = nxt(ar, cur);
        long long peso = e[ar].c;
        if (d[to] > d[cur] + peso) {
          d[to] = d[cur] + peso;
          pai[to] = cur;
          if (!vis[to]) {
            pq.push(pair<long long, long long>(d[to], to));
          }
        }
      }
    } else {
      for (auto ar : g[cur]) {
        long long to = nxt(ar, cur);
        long long peso = e[ar].c;
        if (d[to] > d[cur] + peso) {
          d[to] = d[cur] + peso;
          pai[to] = cur;
          if (!vis[to]) {
            pq.push(pair<long long, long long>(d[to], to));
          }
        }
      }
    }
  }
  if (f > 0) {
    queue<long long> q;
    q.push(f);
    for (long long i = 1; i <= n; i++) vis[i] = 0;
    vis[f] = 1;
    while (!q.empty()) {
      long long cur = q.front();
      q.pop();
      for (long long ar : gr[cur]) {
        long long to = nxt(ar, cur);
        long long peso = e[ar].c;
        if (d[cur] == d[to] + peso) {
          dag[to].push_back(ar);
          dag[cur].push_back(ar);
          if (!vis[to]) {
            vis[to] = 1;
            q.push(to);
          }
        }
      }
    }
    for (long long i = 1; i <= n; i++) {
      vis[i] = tin[i] = 0;
    }
    dfs2(f, -1);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long m, s, t;
  cin >> n >> m >> s >> t;
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(i);
    gr[b].push_back(i);
    e[i] = edge(a, b, c);
  }
  vector<long long> ds, dt;
  DJ(ds, s, t);
  DJ(dt, t, -1);
  long long best = ds[t];
  for (long long i = 0; i < m; i++) {
    if (is_brigde[i]) {
      cout << "YES"
           << "\n";
    } else {
      long long op1 = ds[e[i].a] + dt[e[i].b];
      long long val = (best - 1 - op1);
      if (val >= 1) {
        cout << "CAN " << e[i].c - val << "\n";
      } else
        cout << "NO"
             << "\n";
    }
  }
}
