#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn = 1e5 + 10;
const ll inf = 1e15;

vector< pair< pair< ll , ll> , int > > adj[mxn] , radj[mxn] , dac[mxn] ;
vector< pair< pair<ll , ll >  , ll > > edge;
map< pair< pair< ll , ll > , ll> , int > mp;
ll dis[mxn] , rdis[mxn] , spath[mxn] , rpath[mxn] , low[mxn];
bool eflag[mxn] , nflag[mxn];
void dks(int src , int des)
{
    priority_queue< pair<ll , ll > > PQ;

    dis[src] = 0;
    PQ.push(make_pair(0 , src));
    while(!PQ.empty())
    {
        pair<ll , ll > p = PQ.top();
        PQ.pop();
        for(int i = 0; i < adj[p.second].size(); i++)
        {
            pair<ll , ll > q = adj[p.second][i].first;
            if(dis[q.second] > q.first  + dis[p.second])
            {
                dis[q.second] = dis[p.second] + q.first;
                PQ.push(make_pair((-1)*dis[q.second] , q.second));
            }
        }
    }
}



void rdks(int src , int des)
{
    priority_queue< pair<ll , ll > > PQ;
    rdis[src] = 0;
    PQ.push(make_pair(0 , src));
    while(!PQ.empty())
    {
        pair<ll , ll > p = PQ.top();
        PQ.pop();
        for(int i = 0; i < radj[p.second].size(); i++)
        {
            pair<ll , ll > q = radj[p.second][i].first;
            if(rdis[q.second] > q.first  + rdis[p.second])
            {
                rdis[q.second] = rdis[p.second] + q.first;
                PQ.push(make_pair((-1)*rdis[q.second] , q.second));
            }
        }
    }
}
int cnt = 0;
ll dv[mxn];
void dfs(int u , int par)
{
	//cout<<u<<" "<<par<<endl;
	dv[u] = low[u] = ++cnt;
	nflag[u] = true;
	for(int i = 0; i < dac[u].size(); i++)
	{
		int v  = dac[u][i].first.second;
		if(!nflag[v])
		{
			dfs(v , u);
			low[u] = min(low[u],low[v]);
		}
		else if(v!=par)
		{
			low[u] = min(low[u],dv[v]);
		}
	}
}


void print(int cur , int old)
{
	if(cur < old)
	{
		cout<<"HAPPY"<<endl;
	}
	else if(old < cur)
	{
		cout<<"SAD"<<endl;
	}
	else
	{
		cout<<"SOSO"<<endl;
	}
}

int main()
{
    int n, m , u , v;
    ll w;
    cin>>n>>m;
    for(int i = 0; i < m; i++)
    {
        cin>>u>>v>>w;
        adj[u].push_back(make_pair( make_pair(w,v) , i));
        radj[v].push_back(make_pair(make_pair(w , u) , i));
        edge.push_back(make_pair(make_pair(u , v) , w));
       mp[make_pair(make_pair(u , v), w)] ++;
    }

    for(int i = 0; i < mxn ; i++)
    {
        dis[i] = inf;
        rdis[i] = inf;
    }
    dks(1 , 2);
	rdks(2 , 1);
	/*for(int i = 1; i <= n; i++)
	{
		cout<<dis[i]<<" ";
	}
	cout<<endl;
	for(int i = 1; i <= n; i++)
	{
		cout<<rdis[i]<<" ";
	}
	cout<<endl;*/
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<adj[i].size(); j++)
        {
		//	cout<<(dis[i]+adj[i][j].first.first) <<" "<<dis[adj[i][j].first.second]<<" "<<rdis[i]<<" "<<rdis[adj[i][j].first.second]+adj[i][j].first.first<<endl;
            if(dis[i]+adj[i][j].first.first==dis[adj[i][j].first.second] && rdis[i]==rdis[adj[i][j].first.second]+adj[i][j].first.first)
                {
					dac[i].push_back(adj[i][j]);
					dac[adj[i][j].first.second].push_back(make_pair(make_pair(adj[i][j].first.first, i) , adj[i][j].second));
					eflag[adj[i][j].second] = true;
				}
        }
    }
   
    memset(nflag , false ,sizeof nflag);
    /*for(int i = 1; i <= n; i++)
    {
		cout<<i<<":";
		for(int j = 0; j < dac[i].size(); j++)
		{
			cout<<dac[i][j].first.second<<" ";
		}
		cout<<endl;
	}*/
    dfs(1 , 0);
    /*for(int i = 1; i <= n; i++)
    {
		cout<<low[i]<<" ";
	}
	cout<<endl; */
	
	for(int i = 0; i < edge.size(); i++)
	{
		if(!eflag[i]) continue;
		int u = edge[i].first.first , v = edge[i].first.second;
		if(dv[u] >= low[v] ) eflag[i] = 0;
		
	}
	for(int i =0; i < edge.size(); i++)
	{
		int u = edge[i].first.first , v = edge[i].first.second ;
		ll w = edge[i].second;
		if(eflag[i])
		{
			ll nw = min( inf , dis[v] + w+ rdis[u]);
			print(nw , dis[2]);  
		}
		else
		{
			ll nw = min(dis[2] , dis[v] + w + rdis[u]);
			print(nw , dis[2]);
		}
	}
    return 0;
}
	



Measured memory_bytes: 43864