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 <stdio.h>
#include <algorithm>
using namespace std;

double AB(double num){
	if(num<0)num*=(-1);
	return num;
}

int main(){
	int n,h,m;
	double hh,mm,d;
	for(cin>>n;n>0;n--){
		scanf("%d:%d",&h,&m);
		
		
		mm=360.0*(double)m/60.0;
		hh=360.0*((double)h*60.0+(double)m)/720.0;
		d=AB(hh-mm);
		if(d>180)d=360-d;
		if(d<30)printf("alert\n");
		else if(d>=90)printf("safe\n");
		else printf("warning\n");
	}
	
	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<cmath>
using namespace std;
int a, c, b, n;
double d, e, f;
int main() {
	cin >> n;
	while (cin >> a >> c >> b) {
		d = b * 6;
		e = (a * 60 + b) / 2;
		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++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

int main(){
  int n;
  double h,m;
  string s;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> s;
    int st = s[0] == '0'?1:0;
    h = (atoi)(s.substr(st,s[0]=='0'?1:2).c_str());
    st = s[3] == '0'?4:3;
    m = (atoi)(s.substr(st,s[3]=='0'?1:2).c_str());
    h *= 30;
    m *= 6;
    //       cout << h << " " << m << endl;
    if(0<= abs(h-m)&& abs(h-m) < 30)cout << "alert" << endl;
    else if(90 <= abs(h-m ) && abs(h-m ) <= 180)cout << "safe" << endl;
    else cout << "warning" << endl;  


  }

  return 0;
}



/*
時計の針は

いきなりうごくわけじゃあない
 */

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

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

    int hour_angle = hour * 60 + minutes;
    int minutes_angle = minutes * 12;
    int angle_diff = hour_angle - minutes_angle;
    if ( angle_diff < 0 ) angle_diff = -angle_diff;

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

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

using namespace std;


int main(){

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

	double hour,minute,degree1,degree2,div;

	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;

		div = min(fabs(degree1-degree2),360.0-fabs(degree1-degree2));

		if(div < 30.0){
			printf("alert\n");
		}else if(div < 90.0){
			printf("warnin\n");
		}else{
			printf("safe\n");
		}
	}

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int h, m;
		scanf("%d:%d", &h, &m);
		double t = abs((h/12.0+m/60.0/12.0) - m/60.0);
		if (t > 0.5)
			t = 1 - t;
		t *= 360;

		if (t < 30)
			puts("alert");
		else if (t >= 90)
			puts("safe");
		else
			puts("warning");
	}

	return 0;
}

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

using namespace std;

int different( double h, double m )
{

	h += m / 120;
	double a = h - m;
	if( a < 0 ) a = -a;
	
	if( 360 - a < a ) a = 360 - a;

	return a;
}

int main(int argc, char const* argv[])
{
	double h,m;
	int n;

	cin >> n;

	for( int i = 0;i < n;i++ ){
		scanf("%lf:%lf",&h,&m);

		h *= 30;
		m *= 6;

		double answer = different( h, m );


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

C++: /*#include <iostream>
#include <string>
#include <cmath>*/
#include <bits/stdc++.h>
using namespace std;

string func(int M, int H){
	/*double a = l * 6;
	double b = s * 30.0 + l / 2.0;
	int m = abs(a - b);
	if(180 < m)m = 360 - m;
	if(0 <= m && m < 30)return "alert";
	if(90 <= m && m <= 180)return "safe";
	return "waring";
	if(m > 180)m = 360 - m;
	if(30 <= m){
		if(90 <= m)return "safe";
		return "warning";
	}
	return "alert";*/
	double h = H*30.0 + M/2.0, m = M*6;
     
    int ang = abs(h - m);
    if(ang > 180) ang = 360 - ang;
    if(0 <= ang && ang < 30) {
      cout << "alert" << endl;
    }
    else if(90 <= ang && ang <= 180) {
      cout << "safe" << endl;
    }
    else cout << "warning" << endl;
}

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

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 + minutes / 2;
    double minutes_angle = minutes * 6;
    double angle_diff = hour_angle - minutes_angle;

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

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<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>

#define	min3(a,b,c)	min((a),min((b),(c)))

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=min3(abs(degh-degm),abs(degh-degm-360),abs(degh-degm+360));
		if     (deg<30)	cout<<"alert"<<endl;
		else if(deg<90)	cout<<"warning"<<endl;
		else			cout<<"safe"<<endl;
	}
	return 0;
}