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++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}


	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }
	bool operator < (const Point &p)const { return x != p.x ? x < p.x : y < p.y; }
	bool operator ==(const Point &p)const { return fabs(x - p.x) < EPS&&fabs(y - p.y) < EPS; }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }
};
typedef Point Vector;
struct Segment
{
	Point p1, p2;
};
typedef Segment Line;
class Circle
{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; }//??????
double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }//??????
bool isOrthogonal(Vector a, Vector b) { return fabs(dot(a, b)) < EPS; }//??´??????
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); }
bool isOrthogonal(Line l1, Line l2) { return fabs(dot(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
bool isParallel(Vector a, Vector b) { return fabs(cross(a, b)) < EPS; }//?????????
bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); }
bool isParallel(Line l1, Line l2) { return fabs(cross(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
Point project(Line s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}


int main()
{
	int n; cin >> n;
	while (n--)
	{
		int h, m;
		scanf("%d:%d", &h, &m);
		double r1, r2;
		r1 = 360.0 / 60.0 * (double)m;
		r2 = 360.0 / 12.0*(double)h;
		r2 += 360.0 / 12.0*(double)m/60.0;
		double d = fabs(r1 - r2);
		d = min(d, fabs(360.0 - d));
		if (d < 30.0)cout << "alert" << endl;
		else if (d < 90.0)cout << "warning" << endl;
		else cout << "safe" << endl;
	}
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int a, b, n;
double d, e, f;
char c;
int main() {
	cin >> n;
	while (cin >> a >> c >> b) {
		d = b * 6;
		e = 1.0*(a * 30 + b) / 2.0;
		f = abs(d - e);
		if (f > 180) { f = 360 - f; }
		if (f < 30) { cout << "alert" << endl; }
		else if (f < 90) { cout << "warning" << endl; }
		else { cout << "safe" << 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;
	int angleH = h * 30 + m/12;

	int dist = min(abs(angleH-angleM),360-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 <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int getNum(string str, int pos) {
	int res = str[pos++] - '0';
	while (isdigit(str[pos])) {
		res = res * 10 + str[pos++] - '0';
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	while (n--) {
		string str;
		cin >> str;
		int h = getNum(str, 0), m = getNum(str, 3);
		
		double angle1 = m * 6.0, angle2 = h * 30.0 + m / 60.0;
		double div = abs(angle1 - angle2);
		
		if (div >= 0.0 && div < 30.0)
			puts("alert");
		else if (div >= 90.0 && div <= 180.0)
			puts("safe");
		else
			puts("warning");
	}
	return 0;
}

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

int main(void){
	int n;
	double h,m;
	double ans;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf:%lf",&h,&m);
		h=h*30+m/4;
		m=m*6;
		if(h>m)ans=h-m;
		else ans=m-h;
		if(ans<30 || ans>330)cout << "alert" << endl;
		else if(90<=ans && ans<=270)cout << "safe" << endl;
		else cout << "warning" << endl;
	}
    return 0;
}

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

using namespace std;

int main(){
  int n;

  scanf("%d" ,&n);
  while(n--){
    double h,m;
    scanf("%lf:%lf" ,&h ,&m);
    
    double l = 30*h + m/2;
    double s = m * 6.0;

    double key = fabs(l-s);
    key = min(key,360-key);
  
    if(0 <= key && key < 30){
      puts("alert");
    }else if(90 <= key && key <= 180){
      puts("safe");
    }else{
      puts("warning");
    } 
  }

  return 0;
}

C++: #include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;


int main(){

	int n;
	scanf("%d",&n);

	double hour,minute,degree1,degree2;

	char buf[6];

	for(int i=0; i < n; i++){
		scanf("%s",buf);

		hour = 10*(buf[0]-'0')+(buf[1]-'0');
		minute = 10*(buf[3]-'0')+(buf[4]-'0');

		degree1 = 360*(minute/60);
		degree2 = (60*hour+minute)/2;

		if(fabs(degree1-degree2) <= 30.0){
			printf("alert\n");
		}else if(fabs(degree1-degree2) < 90.0){
			printf("warnin\n");
		}else{
			printf("safe\n");
		}
	}

    return 0;
}

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

string func(int s, int l){
	double a = l * 6;
	double b = s * 30 + l / 2;
	int m = abs(a - b);
	if(m > 180)m = 360 - m;
	if(30 <= m){
		if(90 <= m)return "safe";
		return "warning";
	}
	return "alert";
}

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