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>
using namespace std;

int main(){
    int n;
    int hour, minute;

    cin >> n;

    for(int i=1; i<=n; i++){
        scanf("%d:%d", &hour, &minute);
        double hour_angle;
        double minute_angle;

        minute_angle = minute * 6.0;
        if(minute_angle == 360.0){
            minute_angle = 0.0;
        }
        hour_angle = (hour * 60.0 + minute) * 360.0 / (12.0 * 60.0);
        if(hour_angle == 360.0){
            hour_angle = 0.0;
        }

        double diff = abs(minute_angle - hour_angle);
        if(diff > 180.0){
            diff = 360.0 - diff;
        }

        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;
	double 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,h+=0.5*w,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 <iostream>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        char input[6];
        cin >> input;
        int timeM = (input[0] - '0') * 600 + (input[1] - '0') * 60 + (input[3] - '0') * 10 + (input[4] - '0');
        double littleHand = 6 * (timeM % 60);
        double bigHand = 0.5 * timeM;
        double angle = fabs(littleHand - bigHand);
        if (angle < 30 || 330 < angle) {
            cout << "alert" << endl;
        } else if (90 <= angle && angle <= 270) {
            cout << "safe" << endl;
        } else {
            cout << "warning" << endl;
        }
    }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;
double abvalue(double a,double b) {
	if ((a - b) > 0)return a - b;
	else return (a - b) * -1;
}
int main() {
	int n;
	enum safety{s,w,al};//safe,warning,alart
	vector<safety>l;
	cin >> n;
	for (int i = 0; i < n; i++){
		string ss;
		cin >> ss;
		int a, b;
		double c, d;
		a = (ss[0] - '0') * 10 + (ss[1] - '0');
		b = (ss[3] - '0') * 10 + (ss[4] - '0');
		c = a * 30 + b * 0.5;
		d = b * 6;
		if (abvalue(c, d) < 30)l.push_back(al);
		else if (abvalue(c, d) >= 90)l.push_back(s);
		else l.push_back(w);
	}
	for (safety i : l) {
		if (i == al)cout << "alert";
		else if (i == s)cout << "safe";
		else if (i == w)cout << "warning";
		cout << endl;
	}
	char cha;
	cin >> cha;
}

C++: #include <iostream>
#include <cstdio>
#define EPS 1e-9
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a,b;
		scanf("%d:%d",&a,&b);
		double d1 = a * 30.0 + b * 0.5,d2 = b * 6.0;
		if(d2 < d1){
			double t = d1;
			d1 = d2;
			d2 = t;
		}
		if(d2 - d1 < 30.0 || d2 - d1 > 330.0) cout << "alert" << endl;
		else if(d2 - d1 < 90.0 || d2 - d1 > 270.0) cout << "warning" << endl;
		else cout << "safe" << endl;
	}
	return 0;
}

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

using namespace std;

void StringHandle(string, int&, int&);
int Atoi(string);

int main(){
  int i, n, hour, minute;
  double h_radian, m_radian, radian;
  string clock;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> clock;
    StringHandle(clock, hour, minute);

    h_radian = (60*hour + minute) * M_PI / 360;
    m_radian = minute * M_PI / 30;
    radian = h_radian - m_radian;
    if(radian < 0) radian = -radian;
    if(radian > M_PI) radian = 2*M_PI - radian;

    if(radian < M_PI/6)
      cout << "alert" << endl;
    else if(radian >= M_PI/2)
      cout << "safe" << endl;
    else
      cout << "warning" << endl;
  }

  return 0;
}

void StringHandle(string s, int& h, int& m){
  string s1, s2;
  copy(s.begin(), s.begin()+2, back_inserter(s1));
  copy(s.begin()+3, s.end(), back_inserter(s2));
  h = Atoi(s1);
  m = Atoi(s2);
}

int Atoi(string s){
  int one, ten;
  ten = s[0] - 48;
  one = s[1] - 48;
  return 10*ten + one;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  vector<string> result;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    int h, m;
    double rh, rm;
    scanf("%d:%d\n", &h, &m);
    // (m / 60 * 360) == (h * 6)                                                                                                                  
    rm = m * 6.0;
    rm += (rm > 180 ? -360 : 0);
    // (h / 12 * 360) == (h * 6)                                                                                                                  
    rh = h * 30.0;
    rh += m * 0.5;
    rh += (rh > 180 ? -360 : 0);
    double dis = rh - rm;
    dis *= (dis >= 0 ? 1 : -1);
    if (0.0 <= dis && dis <= 30.0)
      result.push_back("alert");
    else if (90 <= dis)
      result.push_back("safe");
    else
      result.push_back("warning");
  }

  for (int i = 0; i < n; i++)
    cout << result[i] << endl;
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	while (n--) {
		string s; cin >> s;
		double lo = stoi(s.substr(0, 2)) * 5 / 60.0 * 360;
		double sh = stoi(s.substr(3, 2)) / 60.0 * 360;
		double dif = min(fabs(lo - sh), 360.0 - fabs(lo - sh));
		dump(lo); dump(sh); dump(dif);
		if (dif < 30.0)cout << "alert" << endl;
		else if (dif < 90)cout << "warning" << endl;
		else cout << "safe" << endl;
	}
	return 0;
}

C++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
	int h,m;
	char co;
	for(int i=0;i<n;i++){
		double d=0;
	cin>>h>>co>>m;
		d=double(360)/12*h;
		d+=double(360)/12/60*m;
		d-=double(360)/60*m;
		d=abs(d);
		if(d>=0&&d<30)
			cout<<"alert"<<endl;
		else if(d>=90&&d<=180)
			cout<<"safe"<<endl;
		else
			cout<<"warning"<<endl;
	}
}