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 <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.clock", "r", stdin );

	const string mesg[] = { "alert" ,"warning" ,"safe" };
	const double range[] = { 0.0, 30.0, 90.0, 180.0 }; 
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	int i,j;
	for (i = 0; i < n; ++i){
		getline (cin, str );
		str = str.replace(str.find(':'), 1, " ");
		int hour, minute;

		stringstream ss(str);
		ss >> hour >> minute;
		double hour_arg = 30.*hour + minute/2.;
		double minute_arg = 6.*minute;
		double diff = fabs (hour_arg - minute_arg );
		diff = min (diff, 360. - diff ); 
//		cout << "hour_arg  : " << hour_arg << endl;
//		cout << "mintue_arg: " << minute_arg << endl;
//		cout << "diff:       " << diff << endl;

		for (j = 0; j < 3; ++j){
			if (diff >= range[j] && diff < range[j+1]){
				cout << mesg[j] << endl;
				break;
			} // end if
		} // end for
	} // end loop
		
	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,g,c,d; cin>>a>>b>>g>>c>>d;
        double h=(a-'0')*10+(b-'0');
        double m=(c-'0')*10+(d-'0');
        h*=30;
        h+=m/2.0;
        m*=6;
        double cal=min(abs(h-m),360-abs(h-m));
        if(0<=cal&&cal<=30)cout<<"alert"<<endl;
        else if(90<=cal&&cal<=180)cout<<"safe"<<endl;
        else cout<<"warning"<<endl;
    }
}

C++: #include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int h,m;
		char _;
		cin>>h>>_>>m;
		int d=min(abs(h*60+m-12*m) , 720-max(h*60+m,12*m)+min(h*60+m,12*m));
		if(d<30*2){
			cout<<"alert\n";
		}else if(d<90*2){
			cout<<"warning\n";
		}else{
			cout<<"safe\n";
		}
	}
	return 0;
}

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

string func(int M, int H){
	/*double a = l * 6;
	double b = s * 30.0 + l / 2.0;
	int m = abs(a - b);
	if(180 < m)m = 360 - m;
	if(0 <= m && m < 30)return "alert";
	if(90 <= m && m <= 180)return "safe";
	return "waring";
	if(m > 180)m = 360 - m;
	if(30 <= m){
		if(90 <= m)return "safe";
		return "warning";
	}
	return "alert";*/
	double h = H*30.0 + M/2.0, m = M*6;
     
    int ang = abs(h - m);
    if(ang > 180) ang = 360 - ang;
    if(0 <= ang && ang < 30) {
      return "alert";
    }
    else if(90 <= ang && ang <= 180) {
      return "safe";
    }
    return "warning";
}

int main(){
	int n, s, l;cin >> n;
	char c;
	while(n--){
		cin >> s >> c >> l;
		cout << func(s, l) << endl;
	}
	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		double h, m;
		char c;
		cin >> h >> c >> m;

		double hr = 30*h+30*(m/60);
		double mr = 6*m;

		double res = max(hr, mr)-min(hr, mr);

		if(res < 30) {
			cout << "alert" << endl;
		} else if(res < 90) {
			cout << "warning" << endl;
		} else {
			cout << "safe" << endl;
		}
	}

	return 0;
}

C++: #include<bits//stdc++.h>
using namespace std;
int main() {
	double n=0.5,m=6,n2=30;
	int a,b,n4,e=0;
	cin>>n4;
	for(int i=0;i<n4;i++){
		string d;
		cin>>d;
		d+=":";
		string h;
		e=0;
		for(int j=0;j<d.length();j++){
			if(d[j]==':'){
				if(e==0)
					a=atoi(h.c_str());
				else
					b=atoi(h.c_str());
				h="";
				e++;
			}
			else
				h+=d[j];
		}
		double n3,m3;
		n3=0;
		n3+=(a*n2+b*n);
		m3=0;
		m3+=b*m;
		double c=n3-m3;
		if(c<0)
			c=0-c;
		if(360-c<c){
			c=360-c;
		}
		if(c>=90&&c<=180)
			printf("safe\n");
		else if(c>=0&&c<30)
			printf("alert\n");
		else
			printf("warning\n");
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>

using namespace std;

inline int toInt(string s) { stringstream ss(s); int x; ss >> x; return x; }

int main() {
  int n;
  string s;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> s;
    int sh = toInt(s.substr(0, 2));
    int lg = toInt(s.substr(3));
    double argSh = sh*5*6;
    double argLg = lg*6; argSh += argLg/12;
    
    double hen = abs(argSh-argLg);
    hen = min(hen, 360.0-hen);
    if(0<=hen && hen<30) cout << "alert" << endl;
    else if(90<=hen && hen<180) cout << "safe" << endl;
    else cout << "warning"<< endl;
  }
  
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n; cin >> n;
	rep(i, n) {
		double h, m; scanf("%lf:%lf", &h, &m);
		double d = abs(h * 30. - 5.5 * m);
		if (360 - d < d)d = 360 - d;
		if (0. <= d&&d < 30.)puts("alert");
		else if (90. <= d&&d <= 180.)puts("safe");
		else puts("warning");
	}
}