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 <cstdio>
#include <cmath>
using namespace std;

int main(){
    int n;
    for(scanf("%d",&n);n--;){
        double a, b;
        scanf("%lf:%lf",&a,&b);
        a = a*30 + b/20;
        b = b*6;
        if( abs(a-b) < 30 ) puts("alert");
        else if( abs(a-b) < 90 ) puts("warning");
        else puts("safe");
    }
    return 0;
}

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

using namespace std;

int main()
{
	int n;	cin>>n;
	while(n--){
		int h,m;	scanf("%d:%d",&h,&m);
		double degh=30*h+0.5*m,degm=6*m;
		double deg=min(abs(degh-degm),abs(degh-degm-360));
		if     (deg<30)	cout<<"alert"<<endl;
		else if(deg<90)	cout<<"warning"<<endl;
		else			cout<<"safe"<<endl;
	}
	return 0;
}

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

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;

    std::cin >> n;
    
    for (; n--;) {
        int h, m;
        char tmp;
        std::cin >> h >> tmp >> m;

        double angle_h, angle_m, diff;

        angle_h = 30. * h + 0.5 * m;
        angle_m = 6. * m;

        diff = std::abs(angle_h - angle_m);

        if (diff > 180.) {
            diff = 360. - diff;
        }

        if (diff < 30.) {
            std::cout << "alert" << std::endl;
        }
        else if (diff < 90.) {
            std::cout << "warning" << std::endl;
        }
        else {
            std::cout << "safe" << std::endl;
        }
    }

    return 0;
}

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);
		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 <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 <iostream>
#include <string>

std::pair<int, int> stot(const std::string &str) {
	auto idx = str.find(':');
	return std::make_pair<int, int>(stoi(str.substr(0, idx)), stoi(str.substr(idx + 1)));
}

int main() {
	int n;
	std::cin >> n;
	for (auto i = 0; i < n; ++i) {
		std::string arg;
		std::cin >> arg;
		auto time = stot(arg);
		auto dist = (time.first * 60 - time.second * 11) * (time.first * 60 - time.second * 12);
		if (dist < 3600) {
			std::cout << "alert\n";
		}
		else if (dist >= 32400) {
			std::cout << "safe\n";
		}
		else {
			std::cout << "warning\n";
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n;
	cin >> n;
	rep(q, n){
		string s;
		cin >> s;
		int h, m;
		h = stoi(s.substr(0, 2)); m = stoi(s.substr(3, 2));
		double a, b;
		a = 360/(60./m); b = 360/(12./h) + 30/(60./m);
		if(abs(a-b) < 30 || abs(abs(a-b)-360) < 30) cout << "alert" << endl;
		else if(abs(a-b) < 90 || abs(abs(a-b)-360) < 90) cout << "warning" << endl;
		else cout << "safe" << endl;
	}
}

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

int main()
{
	int n;

	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			int h, m;
			char dummy;
			cin >> h >> dummy >> m;

			int hAngle = h * 300 + m * 10 / 2;
			int mAngle = m * 10 * 360 / 60;
			int angle = hAngle > mAngle ? hAngle - mAngle : mAngle - hAngle;
			string message;
			if( ( angle < 300 && angle >= 0 ) || ( angle <= 3600 && angle > 3300 ) ){
				message = "alert";
			}else if( ( angle >= 900 && angle <= 2700 ) ){
				message = "safe";
			}else{
				message = "warning";
			}

			cout << message << endl;
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin>>n;
  while(n--){
    scanf("%d:%d",&a,&b);
    int c=abs(a*30+(3+b)/4-b*6);
    int d=min(c,360-c);
    if(d<30)cout<<"alert"<<endl;
    else if(d<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(c>=90&&c<=180)
			cout<<"safe"<<endl;
		else if(c>=0&&c<30)
			cout<<"alert"<<endl;
		else
			cout<<"warning"<<endl;
	}
}

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


int main(void)
{
	//入力変数(時間)
	int time = 0;
	//入力分変数
	int min = 0;
	//入力回数
	int n = 0; 

	cin >> n;

	//出力
	for (int i = 0; i < n; i++)
	{
		scanf("%d:%d" , &time , &min);

		time *= 5;

		time += min / 12;

		//両方足す(負数になると面倒)
		time += 60;
		min += 60;

		if (time + 5 > min && time - 5 < min)
		{
			cout << "alert";
		}
		else if (time + 15 <= min && time + 30 >= min || time - 15 >= min && time -30 <= min)
		{
			cout << "safe";
		}
		else
		{
			cout << "warning";
		}
		cout << endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>


using namespace std;


int main(){
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        string temp;
        cin>>temp;
        int h=(temp[0]-'0')*10+(temp[1]-'0');
        int m=(temp[3]-'0')*10+(temp[4]-'0');
        
        double h_angle;
        h_angle = 360.0/12.0 * h + (360.0/12.0)/60.0 * m;
        double m_angle;
        m_angle = 360.0/60.0 * m;
        
        double angle = max(h_angle,m_angle)-min(h_angle,m_angle);
        if(angle>180.0)angle=360.0-angle;
        
        if(angle<30.0)cout<<"alert"<<endl;
        else if(angle>=90.0)cout<<"safe"<<endl;
        else cout<<"warning"<<endl;

    }
}