#include <bits/stdc++.h>
using namespace std;
const int MN = 100111;
const long long MOD = 1e9 + 37;
int n, m, s, t;
vector<pair<int, int> > ke[2][MN];
long long f[2][MN];
struct Hash {
  long long x, y;
  Hash(long long x = 0, long long y = 0) : x(x), y(y) {}
  Hash operator+(const Hash& a) const { return Hash(x + a.x, (y + a.y) % MOD); }
  Hash operator*(const Hash& a) const { return Hash(x * a.x, y * a.y % MOD); }
};
bool operator==(const Hash& a, const Hash& b) {
  return a.x == b.x && a.y == b.y;
}
Hash cnt[2][MN];
void go(int start, int turn) {
  set<pair<long long, int> > q;
  for (int i = (1), _b = (n); i <= _b; i++) {
    f[turn][i] = 1e16;
  }
  f[turn][start] = 0;
  cnt[turn][start] = Hash(1, 1);
  q.insert(make_pair(0, start));
  while (!q.empty()) {
    int u = q.begin()->second;
    long long l = q.begin()->first;
    q.erase(q.begin());
    if (l != f[turn][u]) continue;
    for (auto e : ke[turn][u]) {
      int v = e.first, c = e.second;
      if (f[turn][v] > f[turn][u] + c) {
        f[turn][v] = f[turn][u] + c;
        cnt[turn][v] = cnt[turn][u];
        q.insert(make_pair(f[turn][v], v));
      } else if (f[turn][v] == f[turn][u] + c) {
        cnt[turn][v] = cnt[turn][v] + cnt[turn][u];
      }
    }
  }
}
int eu[MN], ev[MN], ec[MN];
int main() {
  ios ::sync_with_stdio(false);
  while (cin >> n >> m >> s >> t) {
    for (int i = (1), _b = (n); i <= _b; i++) {
      ke[0][i].clear();
      ke[1][i].clear();
    }
    for (int i = (1), _b = (m); i <= _b; i++) {
      int u, v, c;
      cin >> u >> v >> c;
      ke[0][u].push_back(make_pair(v, c));
      ke[1][v].push_back(make_pair(u, c));
      eu[i] = u;
      ev[i] = v;
      ec[i] = c;
    }
    go(s, 0);
    go(t, 1);
    for (int i = (1), _b = (m); i <= _b; i++) {
      int u = eu[i], v = ev[i], c = ec[i];
      if (f[0][u] + c + f[1][v] == f[0][t]) {
        if (cnt[0][u] * cnt[1][v] == cnt[0][t]) {
          cout << "YES\n";
          continue;
        } else {
          if (c > 1)
            cout << "CAN 1\n";
          else
            cout << "NO\n";
        }
      } else {
        long long need = f[0][t] - f[0][u] - f[1][v] - 1;
        if (need < 1)
          cout << "NO\n";
        else
          cout << "CAN " << (c - need) << '\n';
      }
    }
    cout << endl;
  }
}
