#include <bits/stdc++.h>
using namespace std;
const long long mod = 811287553;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n, m, s, t, a, b, d;
vector<long long> dist, dist1;
vector<pair<int, int> > grh[2][100000];
vector<pair<pair<int, int>, int> > queries;
set<pair<int, int> > absEdges;
map<pair<int, int>, int> minEdges;
long long reachableCnt[2][100000];
const long long INF = 1000000000000;
void dijkstra(int src, vector<long long>& d, int mode) {
  d.resize(n, INF);
  d[src] = 0;
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, src));
  while (!pq.empty()) {
    long long topD = -pq.top().first;
    int topIdx = pq.top().second;
    pq.pop();
    if (d[topIdx] < topD) continue;
    int sz = grh[mode][topIdx].size();
    for (int i = 0; i < (int)sz; i++) {
      int nIdx = grh[mode][topIdx][i].first;
      int nD = grh[mode][topIdx][i].second;
      long long nD1 = topD + nD;
      if (d[nIdx] > nD1) {
        d[nIdx] = nD1;
        pq.push(make_pair(-nD1, nIdx));
      }
    }
  }
}
int calReachable(int idx, vector<long long>& d, bool rev) {
  if (rev && idx == s) {
    reachableCnt[!rev][idx] = 1;
    return 1;
  }
  if (!rev && idx == t) {
    reachableCnt[!rev][idx] = 1;
    return 1;
  }
  long long& ret = reachableCnt[!rev][idx];
  if (ret != -1) return ret;
  int ret1 = 0;
  int sz = grh[rev][idx].size();
  for (int i = 0; i < (int)sz; i++) {
    int nIdx = grh[rev][idx][i].first;
    int nD = grh[rev][idx][i].second;
    if (d[nIdx] == d[idx] + nD) {
      ret1 += calReachable(nIdx, d, rev);
      ret1 %= mod;
    }
  }
  return ret = (ret1 % mod);
}
int main() {
  cin >> n >> m >> s >> t;
  s--, t--;
  for (int i = 0; i < (int)m; i++) {
    cin >> a >> b >> d;
    a--, b--;
    grh[0][a].push_back(make_pair(b, d));
    grh[1][b].push_back(make_pair(a, d));
    queries.push_back(make_pair(make_pair(a, b), d));
    if (minEdges.count(make_pair(a, b)))
      minEdges[make_pair(a, b)] = min(minEdges[make_pair(a, b)], d);
    else
      minEdges[make_pair(a, b)] = d;
  }
  memset(reachableCnt, -1, sizeof(reachableCnt));
  dijkstra(s, dist, 0);
  dijkstra(t, dist1, 1);
  calReachable(t, dist1, 1);
  calReachable(s, dist, 0);
  for (int i = 0; i < (int)m; i++) {
    int x = queries[i].first.first, y = queries[i].first.second,
        d = queries[i].second;
    if ((((reachableCnt[0][x] * reachableCnt[1][y]) % mod) ==
         reachableCnt[0][t]) &&
        minEdges[make_pair(x, y)] < d) {
      if (minEdges[make_pair(x, y)] == 1)
        cout << "NO" << endl;
      else
        cout << "CAN " << d - minEdges[make_pair(x, y)] + 1 << endl;
    } else {
      long long d1 = dist[x] + dist1[y];
      if ((((reachableCnt[0][x] * reachableCnt[1][y]) % mod) ==
           reachableCnt[0][t])) {
        if (d1 + d == dist[t])
          cout << "YES" << endl;
        else {
          if (d > 1 && d1 + 1 < dist[t])
            cout << "CAN " << d + d1 - (dist[t] - 1) << endl;
          else
            cout << "NO" << endl;
        }
      } else {
        if (d > 1 && d1 + 1 < dist[t])
          cout << "CAN " << d + d1 - (dist[t] - 1) << endl;
        else
          cout << "NO" << endl;
      }
    }
  }
  return 0;
}
