Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), ":")
		h, _ := strconv.Atoi(input[0])
		m, _ := strconv.Atoi(input[1])
		H, M := (30*h+(m/2))*2, (6*m)*2
		if m&1 == 1 {
			H++
		}
		a := H - M
		if a < 0 {
			a = -a
		}
		a2 := 720 - a
		if a2 < a {
			a = a2
		}
		if a < 60 {
			fmt.Println("alert")
		} else if a >= 180 && a <= 360 {
			fmt.Println("safe")
		} else {
			fmt.Println("warning")
		}
	}
}

C++: #include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(void)
{
	int n;
	cin >> n;

	long double h, m;
	while (n--){
		scanf("%Lf:%Lf", &h, &m);
		long double hh = 360 * (h / 12) + 30 * (m / 60);
		long double mm = 360 * (m / 60);
		long double diff = abs(hh - mm);
		// cout << diff << endl;
		if (0 <= diff && diff < 30){
			cout << "alert" << endl;
		}
		else if (90 <= diff && diff <= 180){
			cout << "safe" << endl;
		}
		else {
			cout << "warning" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,h,w,x;
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		h=10*(s[0]-'0')+s[1]-'0';
		w=10*(s[3]-'0')+s[4]-'0';
		h*=30,w*=6;
		if(h>w)x=h-w;
		else x=w-h;
		if(x>180)x=360-x;
		if(x>=90)cout<<"safe"<<endl;
		if(x<30)cout<<"alert"<<endl;
		if(x>=30&&x<90)cout<<"warning"<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#define abs(x) ((x) < 0 ? -(x) : (x))
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main()
{
	int n; scanf("%d", &n);
	rep(i, n) {
		int h, m; scanf("%d:%d", &h, &m);
		int ah = h * 60 + m; if (ah >= 360) ah -= 360;
		int am = 12 * m; if (am >= 360) am -= 360;
		int diff = abs(ah - am)
		if (0 <= diff && diff < 60) puts("alert");
		else if (180 <= diff && diff <= 360) puts("safe");
		else puts("warning");
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    rep(_,n){
        char a,b,c,d; char g;
        cin>>a>>b>>g>>c>>d;
        int l=(c-'0')*10+(d-'0');
        int s=(a-'0')*10+(b-'0');
        l*=6;
        s*=30;
        int val=min(abs(l-s),360-abs(l-s));
        if(0<=val&&val<=30)cout<<"alert"<<endl;
        else if(90<=val&&val<=180)cout<<"safe"<<endl;
        else cout<<"warning"<<endl;
    }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<char,int> P;

static const double eps = 10e-9;

string getAlert(int h,int m){
	int angleM = m * 6 >= 180 ? 360 - m*6 : m*6;
	int angleH = h * 30 + m/12 >= 180 ? 360 - h*30 - m/12 : h*30 + m/12;

	int dist = abs(angleH-angleM);
	if(90 <= dist && dist <= 180) return "safe";
	else if(0 <= dist && dist < 30) return "alert";
	else return "warning";
}

int main(){
	int n,h,m;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			scanf("%d:%d",&h,&m);
			cout << getAlert(h,m) << endl;
		}
	}
}

C++: #include <cstdio>
int main(){
	int n,h,m;
	scanf("%d",&n);
	for(;n--;){
		scanf("%d:%d",&h,&m);
		double s=h*30+m/2.,l=m*6,t,d;
		l<s?t=l,l=s,s=t:0;
		d=s-l+360;
		l-s<d?d=l-s:0;
		d<30?
			puts("alert");
		:
			d<90?
				puts("warning")
			:
				puts("safe");
	}
}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

const double pi = 3.14159265358979;

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0 ; i < n ; i++ ){
		int h, m;
		scanf("%d:%d", &h, &m);
		double hour_hand = (double)h / 12.0 * 360.0 + (double)m / 60.0 * 30.0 + 360.0 ;
		double minute_hand = (double)m / 60.0 * 360.0 + 360.0 ;
		double d = fabs( hour_hand - minute_hand );
		//cout << "h : " << hour_hand - 360.0 << endl;
		//cout << "m : " << minute_hand - 360.0 << endl;
		//cout << "d : " << d << endl;
		if( d < 30.0 ){
			cout << "alert" << endl;
		}else if( d < 90.0 ){
			cout << "warning" << endl;
		}else{
			cout << "safe" << endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(int argc, char const* argv[])
{
	int h,m;
	int n;

	cin >> n;

	for( int i = 0;i < n;i++ ){
		scanf("%d:%d",&h,&m);

		h *= 30;
		m *= 6;

		if( abs( h - m ) >= 0 && abs( h - m ) <= 30 ) cout << "alert" << endl;
		else if( abs( h - m ) >= 90 && abs( h - m ) <= 180 ) cout << "safe" << endl;
		else cout << "warning" << endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//??????
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()

int main()
{
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int h, m;
		scanf("%2d:%2d", &h, &m);

		// [0, 3600)
		int deg_h, deg_m;
		deg_h = 300 * h + 5 * m;
		deg_m = 60 * m;

		if (deg_h > deg_m) swap(deg_h, deg_m);

		int angle = deg_m - deg_h;

		if (angle > 1800) {
			deg_h += 3600;
			angle = deg_h - deg_m;
		}

		if (angle < 300) cout << "alert";
		else if (angle >= 900) cout << "safe";
		else cout << "warning";
		cout << endl;
	}

}