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 <bits/stdc++.h>
using namespace std;
 
// #define int long long
 
/* short */
#define pb push_back
#define print(x) cout << x << '\n'
 
/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}


signed main()
{
  //ios::sync_with_stdio(false);
  int n;

  cin >> n;
  while (n--){
    int h, m;
    scanf("%d:%d", &h, &m);
    double  diff = fabs((h % 12 + m / 60.0) * (360 / 12.0) -  m * 360 / 60.0);

    if (180.0 < diff) diff = 360 - diff;
    if (diff < 30.0){
      print("alert");
    } else if (90.0 <= diff && diff <= 180.0){
      print("safe");
    } else {
      print("warning");
    }
    //cout << "diff: " << diff << endl;
  }

  return (0);
}

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int n;
  scanf("%d",&n);
  while(n --> 0){
    int h,m;
    scanf("%d:%d",&h,&m);
    double hh,mm;
    mm = m * (360.0/60.0);
    hh = (h + (m/60.0)) * (360.0/12.0);
    if(abs(hh-mm) >= 90 && abs(hh-mm) <= 180) puts("safe");
    else if(abs(hh-mm) < 30) puts("alert");
    else puts("warning");
  }
  return 0;
}

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 * 30.0 + minute * 0.5;
        if(hour_angle == 360.0){
            hour_angle = 0.0;
        }

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

        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 <bits/stdc++.h>
using namespace std;

int main(){
  int T;
  cin>>T;
  while(T--){
  int h,m;
  scanf("%d:%d",&h,&m);
  double A,B;
  A=360*(h/12.0);
  B=360*(m/60.0);
  double r=abs(A-B);
  if(r>180)r=360-r;

  if(r<=30)cout<<"alert"<<endl;
  else if(r<90)cout<<"warning"<<endl;
  else cout<<"safe"<<endl;
  
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, h, m;

int main(){
	cin >> n;
	REP(i, n){
		scanf("%d:%d", &h, &m);
		double s = (double)h * 30.0 + (double)m*0.5, l = (double)m * 6.0;
		if (fabs(l - s) < 30)cout << "alert" << endl;
		else if (fabs(l - s) < 90)cout << "warning" << endl;
		else cout << "safe" << 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 angle = (hour * 300 + mini * 5) - (mini * 60);
            if(angle < 0) angle*= -1;
            if(angle >= 0 && angle < 300)
                cout << "alert" << endl;
            else if(angle >= 900 && angle <= 1800)
                cout << "safe" << endl;
            else
                cout << "warning" << endl;
        }
    }
}

C++: #include<stdio.h>

int main(){

int n;
double h,m;
double g=0,gm=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lf:%lf",&h,&m);
g=30*h;gm=6*m;
g+=(30/60*m);
double H=0;
H=gm-g;
if(H<0)H*=-1;
if(H>180)H=360-H;


if(H<30)printf("alert\n");
else if(H<90)printf("warning\n");
else if(H<=180)printf("safe\n");
}
return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    rep(_,n){
        char a,b,g,c,d; cin>>a>>b>>g>>c>>d;
        double h=(a-'0')*10+(b-'0');
        double m=(c-'0')*10+(d-'0');
        double hoge=h*30;
        h=m/2.0+hoge;
        m*=6;
        double cal=min((ld)abs((ld)h-(ld)m),(ld)360-(ld)abs((ld)h-(ld)m));
        
        //cout<<h<<" "<<m<<" "<<cal<<endl;
        if(cal<=30)cout<<"alert"<<endl;
        else if(90<=cal&&cal<=180)cout<<"safe"<<endl;
        else cout<<"warning"<<endl;
    }
}

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

int main(){

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

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

		long double ang ;
		ang = 6 * m - (30 * h + 30 * ((long double)m / 60));
		ang = std::abs(ang);
		if (ang > 180)ang -= 180;

		if (0 <= ang && ang < 30)printf("alert\n");
		else if (90 <= ang && ang <= 180)printf("safe\n");
		else printf("warning\n");
	}

	return 0;
}