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>
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define min(x, y) ((x) < (y) ? (x) : (y))
int main()
{
	int n; scanf("%d", &n);
	rep(i, n) {
		int h, m; scanf("%d:%d", &h, &m);
		double ah = 0.5 * (60 * h + m);
		double am = 6.0 * m;
		double d = fabs(ah - am);
		d = min(d, 360.0 - d);

//printf("%02d:%02d, %4.1f %4.1f, d=%.1f ", h, m, 0.5 * ah, 0.5 * am, d);
		if (d < 30) puts("alert");
		else if (d < 90) puts("warning");
		else puts("safe");
	}
	return 0;
}

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

#define DEBUG(x) // cerr << #x << " = " << x << endl

const double EPS = 1e-8;

double deg_long(int hh, int mm) {
    hh %= 12;
    long double deg = (1.0 * 360) * hh / 12;
    deg += (1.0 * 360 / 12) * mm / 60;
    if(deg > 180) deg -= 360;
    return deg;
}

double deg_short(int mm) {
    double deg = 1.0 * 360 * mm / 60;
    if(deg > 180) deg -= 360;
    return deg;
}

int main() {
    int N; scanf("%d", &N);
    while(N--) {
        int hh, mm; scanf("%d:%d", &hh, &mm);
        double diff = abs(deg_long(hh, mm) - deg_short(mm));
        DEBUG(diff);
        if (diff < 30 - EPS) puts("alert");
        else if(90 - EPS < diff) puts("safe");
        else puts("warning");
    }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n,h,m;
int a,b,c,d,A,B;
char ch;
int main(){
  cin>>n;
  while(n--){
    cin>>h>>ch>>m;
    a=h*30+(m/12)*6;
    b=m*6;
    
    c=0;
    A=a;
    B=b;

    while(A!=B){
      A+=6;
      c+=6;
      if(A>=360)A-=360;
    }
      
    d=0;
    A=a;
    B=b;
    while(A!=B){
      B+=6;
      d+=6;
      if(B>=360)B-=360;
      
    }

    //cout << a<< ' '<<b<<' '<<c<<endl;
    
    c=min(c,d);

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

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<string>a(vector<string>b) {
	vector<string>ans(8, string(8, 'a'));
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) {
			ans[7 - j][i] = b[i][j];
		}
	}
	return ans;
}

int main() {
	int N; cin >> N;
	while (N--) {
		int h, m;
		scanf("%d:%d", &h, &m);
		m = h * 60 + m;
		int ans = 11*m;
		ans %= 720;
		if (ans >= 360)ans = 720 - ans;
		if (ans < 60)cout << "alert" << endl;
		else if(ans < 180)cout << "warning" << endl;
		else cout << "safe" << endl;
	}
	return 0;
}

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 (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++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		int h, m;
		scanf("%d:%d", &h, &m);
		
		double arg = fabs(h*5 + m/12.0 - m);
		if(arg >= 30.0)
			arg = 60.0 - arg;
		if(arg < 5.0)
			puts("alert");
		else if(arg < 15.0)
			puts("warning");
		else
			puts("safe");
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n,h,m;
int a,b,c,d;
char ch;
int main(){
  cin>>n;
  while(n--){
    cin>>h>>ch>>m;
    a=h*30+m/2;
    b=m*6;
     
    
    c=max(a,b)-min(a,b);
    if(c>180){
      c=360-c;
    }
 
    //cout << a<< ' '<<b<<' '<<c<<endl;
     
    if(0<=c&&c<30){
      cout<<"alert"<<endl;
    }else if(90<=c&&c<=180){
      cout<<"safe"<<endl;
    }else{
      cout<<"warning"<<endl;
    }
     
  }
  return 0;
}

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)
#define EPS (1e-8)

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

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 / 2.0;
		double div = abs(angle1 - angle2);
		cout << div << endl;
		
		if (div >= -EPS && div < 30.0 - EPS)
			puts("alert");
		else if (div >= 90.0 - EPS && div <= 180.0 + EPS)
			puts("safe");
		else
			puts("warning");
	}
	return 0;
}

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

int main() {
  int n;
  scanf("%d", &n);
  for (int k=0; k<n; k++) {
    int h, m;
    scanf("%d:%d", &h, &m);
    double t = (double)(h*60+m)/(12*60) * 360;
    double c = (double)m/60 * 360;
    if (t > c) swap(t, c);
    double sa = c - t;
    if (sa > 180) sa = 360 - sa;
    if (sa < 30) cout << "alert" << endl;
    else if (sa >= 90) cout << "safe" << endl;
    else cout << "warning" << endl;
  }
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        rep(i,n){
            double hour, mini;
            scanf("%lf%*c%lf", &hour, &mini);
            double angle1 = (hour * 300 + mini * 5);
            double angle2 = (mini * 60);
            double angle = sqrt((angle1 - angle2) * (angle1 - angle2));
            if(angle > 1800) angle = 3600 - angle;
            if(angle >= 0 && angle < 300)
                cout << "alert" << endl;
            else if(angle >= 900 && angle <= 1800)
                cout << "safe" << endl;
            else
                cout << "warning" << endl;
        }
    }
}

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