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;
void solve();
int main() {
	int n;cin>>n;
	for(int i=0;i<n;i++)solve();
}
void solve(){
	int a,b;
	scanf("%d:%d",&a,&b);
	double d=abs((a*30+(double)b/2)-b*6);
	d=min(d,360-d);
	if(d<30)cout<<"alert\n";
	else if(d<90)cout<<"warning\n";
	else cout<<"safe\n";
	return;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		string str;
		double lg,sh;
		cin>>str;
		lg=atoi(str.substr(0,2).c_str())*30;
		sh=((atoi(str.substr(3,2).c_str())))*6;
		lg+=((double)sh/12);
		double dis=abs(lg-sh);
		dis=min(dis,360-dis);
		if((dis>0||EQ(dis,0))&&dis<30){
			cout<<"alert"<<endl;
		}
		else if((dis>90||EQ(dis,90))&&(dis<180||EQ(dis,180))){
			cout<<"safe"<<endl;
		}
		else{
			cout<<"warning"<<endl;
		}
	}
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int hh,mm;
		char cc;
		cin>>hh>>cc>>mm;
		double tyousin=mm*6;
		double tansin=hh*30+mm*0.5;
		int sita=abs(tyousin-tansin);
		if(sita<30)cout<<"alert"<<endl;
		else if(sita>=90 &&sita<=180)cout<<"safe"<<endl;
		else cout<<"warning"<<endl;
	}
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  double h,m;
  char c;
  rep(i,n){
    cin >> h >> c >> m;
    h = 30 * h + 0.5*m;
    m = 6 * m;
    if(abs(h-m) < 30.0){
      cout << "alert"<<endl;
    }
    else if(abs(h-m) < 90.0){
      cout << "warning"<<endl;
    }
    else{
      cout << "safe"<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.clock", "r", stdin );

	const string mesg[] = { "alert" ,"warning" ,"safe" };
	const double range[] = { 0.0, 30.0, 90.0, 180.0 }; 
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	int i,j;
	for (i = 0; i < n; ++i){
		getline (cin, str );
		str = str.replace(str.find(':'), 1, " ");
		int hour, minute;

		stringstream ss(str);
		ss >> hour >> minute;
		double hour_arg = 30.*hour + minute/2.;
		double minute_arg = 6.*minute;
//		double diff_h = min (hour_arg, 360. - hour_arg);
//		double diff_m = min (minute_arg, 360. - minute_arg);
		double diff = fabs (hour_arg - minute_arg ); 
		diff = min (diff, 360. - diff ); 
//		cout << "hour_arg  : " << hour_arg << endl;
//		cout << "mintue_arg: " << minute_arg << endl;
//		cout << "diff:       " << diff << endl;

		if (diff >= 0.0 && diff < 30.0){
			cout << mesg[0] << endl;
		}else if (diff >= 30.0 && diff < 90.0){
			cout << mesg[1] << endl;
		}else{
			cout << mesg[2] << endl;
		} // end if
/*		
		for (j = 0; j < 3; ++j){
			if (diff >= range[j] && diff < range[j+1]){
				cout << mesg[j] << endl;
				break;
			} // end if
		} // end for
*/
	} // end loop
		
	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;
    double deg = (1.0 * 360) * hh / 12;
    deg += (1.0 * 360 / 12) * mm / 60;
    return deg;
}

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

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 (-EPS < diff && diff < 30 - EPS) puts("alert");
        else if(90 - EPS < diff && diff < 180 + EPS) puts("safe");
        else puts("warning");
    }
}

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;
    }
}