#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, m;
ll dist_s[111111], dist_t[111111];
int ans[111111], low[111111], num[111111], N;
vector<vector<tuple<int,int,int>>> e, re, g;

void rec(int cur, int pid){
	num[cur] = low[cur] = ++N;
	vector<tuple<int,int,int>> es;
	for(auto p : g[cur]){
		int to, cost, id; tie(to, cost, id) = p;
		if(id == pid) continue;
		if(num[to] == 0){
			rec(to, id);
			low[cur] = min(low[cur], low[to]);
			es.emplace_back(p);
		}
		else low[cur] = min(low[cur], num[to]);
	}
	for(auto p : es){
		int to, cost, id; tie(to, cost, id) = p;
		//dbg(cur, to, num[cur], low[to]);
		if(low[to] > num[cur]) ans[id] = 1;
	}
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> m;
	e.resize(n); re.resize(n); g.resize(n);
	rep(i, m){
		int a, b, c; cin >> a >> b >> c; a--; b--;
		e[a].emplace_back(b, c, i);
		re[b].emplace_back(a, c, i);
	}
	auto dij = [](ll *dist, int s, const vector<vector<tuple<int,int,int>>> &e){
		priority_queue<pair<ll,int>> q;
		q.emplace(0, s);
		rep(i, n) dist[i] = 1e18;
		dist[s] = 0;
		
		while(!q.empty()){
			int c; ll co;
			tie(co, c) = q.top(); q.pop();
			if(dist[c] < -co) continue;
			
			for(auto to : e[c]){
				ll nco = -co + get<1>(to);
				if(dist[get<0>(to)] <= nco) continue;
				dist[get<0>(to)] = -co + get<1>(to);
				q.emplace(co - get<1>(to), get<0>(to));
			}
		}
	};
	dij(dist_s, 0, e);
	dij(dist_t, 1, re);
	{
		ll dist = dist_s[1];
		rep(i, n) for(auto p : e[i]){
			int to, cost, id; tie(to, cost, id) = p;
			if(dist_s[i] + cost + dist_t[to] == dist){
				g[i].emplace_back(to, cost, id);
				g[to].emplace_back(i, cost, id);
			}
			else{
				ans[id] = dist_s[to] + cost + dist_t[i] < dist ? -1 : 0;
			}
		}
		rec(0, -1);
		rep(i, m){
			if(ans[i] < 0) cout << "HAPPY" << endl;
			else cout << (ans[i] == 0 ? "SOSO" : "SAD") << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 31504