#include <bits/stdc++.h>
using namespace std;
class cesta {
 public:
  long long a, c;
  bool operator<(const cesta &first) const {
    return (c != first.c) ? (c < first.c) : (a < first.a);
  }
};
const int MAXN = 200000;
const int MOD = 1000000007;
const long long INF = (1LL << 60);
long long n, m, a, b, c, poc, zav, minn, dfscnt;
long long dis1[MAXN + 5];
long long dis2[MAXN + 5];
pair<pair<long long, long long>, long long> in[MAXN + 5];
bool bio[MAXN + 5];
int cntp1[MAXN + 5];
int cntp2[MAXN + 5];
vector<pair<long long, long long> > v1[MAXN + 5];
vector<pair<long long, long long> > v2[MAXN + 5];
vector<long long> v3[MAXN + 5];
set<cesta> s1;
set<cesta> s2;
set<pair<int, int> > yess;
set<pair<int, int> >::iterator it;
map<pair<long long, long long>, int> mapa;
map<pair<long long, long long>, bool> mapcnt;
void dfs(int curr) {
  cntp2[curr]++;
  if (cntp1[curr] > cntp2[curr]) {
    return;
  }
  if (cntp1[curr] > 1 && cntp1[curr] == cntp2[curr]) {
    dfscnt -= (cntp1[curr] - 1);
  }
  dfscnt += v3[curr].size() - 1;
  for (int i = (0), _for = (v3[curr].size()); i < _for; ++i) {
    if (dfscnt == 1) yess.insert(make_pair(curr, v3[curr][i]));
    dfs(v3[curr][i]);
  }
}
void di1() {
  while (s1.size()) {
    cesta first = *(s1.begin());
    a = first.a;
    c = first.c;
    s1.erase(s1.begin());
    if (dis1[a] != INF) continue;
    dis1[a] = c;
    while (v1[a].size()) {
      cesta first;
      first.a = v1[a].back().first;
      first.c = v1[a].back().second + dis1[a];
      v1[a].pop_back();
      if (dis1[first.a] == INF) s1.insert(first);
    }
  }
}
void di2() {
  while (s2.size()) {
    cesta first = *(s2.begin());
    a = first.a;
    c = first.c;
    s2.erase(s2.begin());
    if (dis2[a] != INF) continue;
    dis2[a] = c;
    while (v2[a].size()) {
      cesta first;
      first.a = v2[a].back().first;
      first.c = v2[a].back().second + dis2[a];
      v2[a].pop_back();
      if (dis2[first.a] == INF) s2.insert(first);
    }
  }
}
void init() {
  for (int i = (0), _for = (n); i < _for; ++i) dis1[i] = INF;
  dis1[poc] = 0;
  for (int i = (0), _for = (n); i < _for; ++i) dis2[i] = INF;
  dis2[zav] = 0;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d", &n, &m, &poc, &zav);
  poc--;
  zav--;
  init();
  for (int i = 0; i < m; ++i) {
    scanf("%I64d%I64d%I64d", &a, &b, &c);
    a--;
    b--;
    int cm = mapa[make_pair(a, b)];
    if (cm == 0)
      mapa[make_pair(a, b)] = c;
    else if (cm == c) {
      mapcnt[make_pair(a, b)] = 1;
    } else if (cm > c) {
      mapa[make_pair(a, b)] = c;
      mapcnt[make_pair(a, b)] = 0;
    }
    v1[a].push_back(make_pair(b, c));
    v2[b].push_back(make_pair(a, c));
    in[i] = make_pair(make_pair(a, b), c);
  }
  while (v1[poc].size()) {
    cesta c;
    c.a = v1[poc].back().first;
    c.c = v1[poc].back().second;
    v1[poc].pop_back();
    s1.insert(c);
  }
  di1();
  while (v2[zav].size()) {
    cesta c;
    c.a = v2[zav].back().first;
    c.c = v2[zav].back().second;
    v2[zav].pop_back();
    s2.insert(c);
  }
  di2();
  minn = dis1[zav];
  for (int i = (0), _for = (m); i < _for; ++i) {
    if (dis1[in[i].first.first] + dis2[in[i].first.second] + in[i].second ==
        minn) {
      v3[in[i].first.first].push_back(in[i].first.second);
      cntp1[in[i].first.second]++;
    }
  }
  dfscnt = 1;
  dfs(poc);
  for (it = yess.begin(); it != yess.end(); ++it) {
    pair<int, int> pom = *it;
  }
  for (int i = (0), _for = (m); i < _for; ++i) {
    if (yess.count(make_pair(in[i].first.first, in[i].first.second)) > 0) {
      long long q = in[i].first.first;
      long long w = in[i].first.second;
      if (mapcnt[make_pair(q, w)] == 1) {
        if (mapa[make_pair(q, w)] == 1) {
          puts("NO");
          continue;
        }
        printf("CAN %I64d\n", in[i].second - mapa[make_pair(q, w)] + 1);
        continue;
      }
      if (mapa[make_pair(q, w)] == in[i].second) {
        puts("YES");
        continue;
      }
      if (mapa[make_pair(q, w)] == 1) {
        puts("NO");
        continue;
      }
      printf("CAN %I64d\n", in[i].second - mapa[make_pair(q, w)] + 1);
      continue;
    }
    long long q = dis1[in[i].first.first];
    long long w = dis2[in[i].first.second];
    if (q + w >= minn - 1) {
      puts("NO");
      continue;
    }
    printf("CAN %I64d\n", in[i].second - minn + q + w + 1);
  }
  return 0;
}
