#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int s;
int t;
struct st {
  int l;
  int r;
  long long int cost;
  st(int l_, int r_, long long int c_) {
    l = l_;
    r = r_;
    cost = c_;
  }
};
vector<st> vv;
vector<pair<int, int> > v[100002];
vector<pair<int, int> > V[100002];
long long int dist[100002];
long long int dist2[100002];
map<pair<int, pair<int, int> >, int> mp;
void me() {
  for (int i = 0; i < 100002; i++) {
    dist[i] = dist2[i] = LLONG_MAX / 3LL;
  }
}
void d() {
  priority_queue<pair<long long int, int>, vector<pair<long long int, int> >,
                 greater<pair<long long int, int> > >
      q;
  dist[s] = 0;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    int g = q.top().second;
    if (dist[g] != q.top().first) {
      q.pop();
      continue;
    }
    q.pop();
    if (g == t) {
      continue;
    }
    for (int i = 0; i < v[g].size(); i++) {
      int &go = v[g][i].second;
      long long int ne = dist[g] + vv[v[g][i].first].cost;
      if (dist[go] > ne) {
        dist[go] = ne;
        q.push(make_pair(dist[go], go));
      }
    }
  }
}
void d2() {
  priority_queue<pair<long long int, int>, vector<pair<long long int, int> >,
                 greater<pair<long long int, int> > >
      q;
  dist2[t] = 0;
  q.push(make_pair(0, t));
  while (!q.empty()) {
    int g = q.top().second;
    if (dist2[g] != q.top().first) {
      q.pop();
      continue;
    }
    q.pop();
    if (g == s) {
      continue;
    }
    for (int i = 0; i < V[g].size(); i++) {
      int &go = V[g][i].second;
      long long int ne = dist2[g] + vv[V[g][i].first].cost;
      if (dist2[go] > ne) {
        dist2[go] = ne;
        q.push(make_pair(dist2[go], go));
      }
    }
  }
}
vector<int> g[100002];
bool fl[100002];
bool uu[100002];
inline void init() {
  queue<int> q;
  q.push(t);
  while (!q.empty()) {
    int b = q.front();
    uu[b] = true;
    q.pop();
    for (int i = 0; i < V[b].size(); i++) {
      if (dist[V[b][i].second] == LLONG_MAX / 3LL) {
        continue;
      }
      if (dist[V[b][i].second] + vv[V[b][i].first].cost == dist[b]) {
        g[V[b][i].second].push_back(b);
        g[b].push_back(V[b][i].second);
        if (!uu[V[b][i].second]) {
          q.push(V[b][i].second);
          uu[V[b][i].second] = true;
        }
        fl[V[b][i].first] = true;
      }
    }
  }
}
bool use[100002];
int ord[100002];
int siz = 0;
int lo[100002];
inline void dfs(int b, int pre = -1) {
  use[b] = true;
  ord[b] = siz;
  siz++;
  lo[b] = ord[b];
  int countt = 0;
  for (int i = 0; i < g[b].size(); i++) {
    if (use[g[b][i]] && g[b][i] != pre) {
      lo[b] = min(lo[b], ord[g[b][i]]);
      continue;
    }
    if (use[g[b][i]]) {
      countt++;
      if (countt > 1) {
        lo[b] = min(lo[b], ord[g[b][i]]);
      }
      continue;
    }
    dfs(g[b][i], b);
    lo[b] = min(lo[b], lo[g[b][i]]);
  }
}
set<pair<int, int> > sss;
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  s--;
  t--;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    vv.push_back(st(a, b, c));
    v[a].push_back(make_pair(i, b));
    V[b].push_back(make_pair(i, a));
  }
  me();
  d();
  d2();
  if (dist[t] == LLONG_MAX / 3LL) {
    for (int i = 0; i < m; i++) {
      puts("NO");
    }
    return 0;
  }
  init();
  dfs(s);
  for (int i = 0; i < vv.size(); i++) {
    int a = vv[i].l;
    int b = vv[i].r;
    if (dist[a] == LLONG_MAX / 3LL || dist[b] == LLONG_MAX / 3LL ||
        dist2[a] == LLONG_MAX / 3LL || dist2[b] == LLONG_MAX / 3LL) {
      puts("NO");
      continue;
    }
    if (g[a].size() == 0 || fl[i] == false) {
    } else {
      if (0) {
      } else {
        if (ord[a] > ord[b]) {
          swap(a, b);
        }
        if (ord[a] < lo[b]) {
          puts("YES");
          continue;
        }
      }
    }
    a = vv[i].l;
    b = vv[i].r;
    long long int costt = dist[a] + dist2[b] + vv[i].cost;
    long long int need = dist[t] - 1LL;
    costt -= need;
    if (costt >= vv[i].cost) {
      puts("NO");
      continue;
    }
    printf("CAN %I64d\n", costt);
  }
  return 0;
}
