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++: //29
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    int h,m;
    (cin>>h).ignore()>>m;
    double hh=h/12.+m/60./12;
    double mm=m/60.;
    double d=fabs(hh-mm);
    if(d>.5){
      d=1-d;
    }
    if(d<30./360){
      cout<<"alert"<<endl;
    }else if(d<90./360){
      cout<<"warning"<<endl;
    }else{
      cout<<"safe"<<endl;
    }
  }
  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;
    return deg;
}

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

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

C++: #include <stdio.h>
int main() {
	
	int n,i,h,m,a,b,c,d;
	
	for(scanf("%d",&n),i=n;i--;){
		scanf("%d:%d",&h,&m);
		
		a = 6 * m;
		b = 30 * h + m / 2;
		
		c = (b-a);
		d = (b-360)-a;
		
		c=c<0?-c:c;
		d=d<0?-d:d;
		
		if(c<30 || d<30)puts("alert");
		else if((c>=90 && c<=180) || (d>=90 && d<=180))puts("safe");
		else puts("warning");
	}
	return 0;
}

C++: #include <stdio.h>

#define ABS(X) ((X)<0?-(X):(X))

int main(void){
    int n;
    int h,m;
    double angleH, angleM, dAngle;
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%02d:%02d",&h, &m);
        //printf("%d, %d\n", h, m);
        angleM = 360*m/60.0;
        angleH = 360*h/12.0 + (360/12)*m/60.0;
        dAngle = (360 + angleM - angleH);
        while (dAngle > 180) dAngle -= 180;
        //printf("agl:%lf\n", dAngle);
        if (dAngle < 30){
            puts("alert");
        } else if (dAngle < 90){
            puts("warning");
        } else {
            puts("safe");
        }
    }
    
    return 0;
}

C++: #if 0
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(_Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,_Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

#endif

#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n)           REPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
typedef unsigned long long ull;

int main(){
    int n;
    cin >> n;       // 10^4
    REP(i,n){
        int h, m; char c;
        cin >> h >> c >> m;   // hh:mm

        int th1 = 3600/12*h + 300/60*m;
        int th2 = 3600/60*m;
        int th_diff = abs(th1-th2);
        if(th_diff > 1800) th_diff = 3600-th_diff;
        //printf("th1 = %d, th2 = %d\n", th1, th2);
        if(th_diff < 300){
            cout << "alert" << endl;
        } else if(th_diff >= 900){
            cout << "safe" << endl;
        } else {
            cout << "warning" << 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<30)
			cout<<"alert"<<endl;
		else if(d>=90&&d<180)
			cout<<"safe"<<endl;
		else
			cout<<"warning"<<endl;
	}
}

C++: #include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    int n;
    cin>>n;
    while(n--){
        int h,m;
        scanf("%d:%d",&h,&m);
        double h_angle,m_angle;
        h_angle = h/12.0 + m/720.0;
        m_angle = m/60.0;
        double d = fabs(h_angle - m_angle);
        d = min(d,1.0-d);
        if(d < 1.0/12)cout<<"alert"<<endl;
        else if(d >= 1.0/4)cout<<"safe"<<endl;
        else cout<<"warning"<<endl;
    }


    return 0;
}