#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <limits>
#include <tuple>

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    int id;
    Edge(int src = -1, int dst = -1, Cost cost = 1, int id = -1)
        : src(src), dst(dst), cost(cost), id(id){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

using lint = long long;
constexpr lint INF = 1LL << 60;

template <class Cost>
std::vector<Cost> dijkstra(const Graph<Cost>& graph, int s) {
    std::vector<Cost> dist(graph.size(), INF);
    dist[s] = 0;
    MinHeap<std::pair<Cost, int>> que;
    que.emplace(0, s);

    while (!que.empty()) {
        int v;
        Cost d;
        std::tie(d, v) = que.top();
        que.pop();
        if (d > dist[v]) continue;

        for (auto e : graph[v]) {
            if (dist[e.dst] <= dist[v] + e.cost) continue;
            dist[e.dst] = dist[v] + e.cost;
            que.emplace(dist[e.dst], e.dst);
        }
    }
    return dist;
}

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void solve() {
    int n, m;
    std::cin >> n >> m;

    Graph<lint> graph(n), rgraph(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        lint d;
        std::cin >> u >> v >> d;
        --u, --v;
        graph[u].emplace_back(u, v, d, i);
        rgraph[v].emplace_back(v, u, d, i);
    }

    auto sdist = dijkstra(graph, 0);
    auto gdist = dijkstra(rgraph, 1);
    lint dmin = sdist[1];

    std::vector<int> ans(m, -1);
    for (int u = 0; u < n; ++u) {
        for (auto e : graph[u]) {
            int v = e.dst;
            lint nd = sdist[v] + e.cost + gdist[u];

            if (nd < dmin) {
                ans[e.id] = 0;
            } else if (nd == dmin) {
                ans[e.id] = 1;
            }
        }
    }

    std::vector<mint> spat(n, 0), gpat(n, 0);
    std::vector<int> vs(n);
    std::iota(vs.begin(), vs.end(), 0);

    {
        std::sort(vs.begin(), vs.end(),
                  [&](int u, int v) { return sdist[u] < sdist[v]; });

        spat[0] = 1;
        for (auto u : vs) {
            for (auto e : graph[u]) {
                int v = e.dst;
                auto nd = sdist[u] + e.cost + gdist[v];

                if (nd > dmin) {
                    if (ans[e.id] == -1) ans[e.id] = 1;  // SOSO
                    continue;
                }

                spat[v] += spat[u];
            }
        }
    }

    {
        std::sort(vs.begin(), vs.end(),
                  [&](int u, int v) { return gdist[u] < gdist[v]; });

        gpat[1] = 1;
        for (auto u : vs) {
            for (auto e : rgraph[u]) {
                int v = e.dst;
                auto nd = gdist[u] + e.cost + sdist[v];

                if (nd > dmin) continue;

                gpat[v] += gpat[u];
            }
        }
    }

    for (auto u : vs) {
        for (auto e : graph[u]) {
            int v = e.dst;
            if (ans[e.id] != -1) continue;
            ans[e.id] = (spat[u] * gpat[v] == spat[1] ? 2 : 1);
        }
    }

    std::vector<std::string> ss{"HAPPY", "SOSO", "SAD"};
    for (auto a : ans) std::cout << ss[a] << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}



Measured memory_bytes: 17840