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 <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;
        if(0<=abs(l-s)&&abs(l-s)<=30)cout<<"alert"<<endl;
        else if(90<=abs(l-s)&&abs(l-s)<=180)cout<<"safe"<<endl;
        else cout<<"warning"<<endl;
    }
}

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;
	}

}

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

int main()
{
  int n;
  cin >> n;
  for (int dataset=0; dataset<n; dataset++)
  {
    char dummy;
    double hour,minutes;
    cin >> hour >> dummy >> minutes;

    double hour_angle = hour * 30;
    double minutes_angle = minutes * 6;
    double angle_diff = hour_angle - minutes_angle;
    if ( angle_diff < 0 ) angle_diff = -angle_diff;

    if ( 0 <= angle_diff && angle_diff <= 30 )
    {
      cout << "alert" << endl;
    }
    else if ( 90 <= angle_diff && angle_diff <= 180 )
    {
      cout << "safe" << endl;
    }
    else
    {
      cout << "warning" << endl;
    }
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a,b;
  cin>>n;
  while(n--){
    scanf("%d:%d",&a,&b);
    a*=5;
    int y=abs(b-a),x=abs(60-b+a);
    if(min(y,x)<=5)cout<<"alert"<<endl;
    else if(min(y,x)<15)cout<<"warning"<<endl;
    else cout<<"safe"<<endl;
  }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

#define rep(i, n) for(int i = 0; i < n; i++)

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int main(){
	int n;
	cin >> n;
	string s;
	rep(i, n){
		cin >> s;
		int h = (s[0]-'0') * 10 + s[1] - '0';
		int m = (s[3]-'0') * 10 + s[4] - '0';
		double angle1 = h * 30 + (double)m / 2;
		double angle2 = m * 6;
		double d = abs(angle1 - angle2);
		if(d > 180.0) d = 360.0 - d;
		if(d < 30.0) {
			cout << "alert" << endl;
		}else if(90.0 - EPS < d) cout << "safe" << endl;
		else cout << "warning" << endl;
	}
	return 0;
}