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 <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) puts("alert");
        else if(90 <= diff) puts("safe");
        else puts("warning");
    }
}

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/12);
    b=m*6;
    
   
    c=max(a,b)-min(a,b);
    if(c>180)c=min(a,b)+(360-max(a,b));

    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;

int main(){
  int n,h,s;
  double a,b,ans;
  cin>>n;
  while(n--){
    scanf("%d:%d",&h,&s);
    b=s*6;
    a=h*30+30*b/360;
    ans=abs(a-b);
    cout<<ans<<endl;
    if(ans>180)ans=360-ans;
    if(0<=ans&&ans<30)cout<<"alert"<<endl;
    else if(90<=ans&&ans<=180)cout<<"safe"<<endl;
    else cout<<"warning"<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  cin>>n;
  REP(i,n){
    int h,m;
    scanf("%d:%d",&h,&m);
    if(h>=12) h -= 12;
    double t1 = h * 30 + (double)m/4;  
    double t2 = m * 6; 
    if(abs(t1-t2)<30||abs(t1-t2)>330){
      cout<<"alert"<<endl;
    }else if(abs(t1-t2)>=90&&abs(t1-t2)<=270){
      cout<<"safe"<<endl;
    }else{
      cout<<"warning"<<endl;
    }
  }
  return 0;
}

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 = 360 - ang;

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

	return 0;
}

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

using namespace std;

int different( int h, int m )
{
	int a = h - m;
	if( a < 0 ) a = -a;
	
	if( 360 - a < a ) a = 360 - a;

	return a;
}

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

	cin >> n;

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

		h *= 30;
		m *= 6;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};

int main() {
  int n;
  cin >> n;

  REP(i, n) {
    string s;
    cin >> s;
    int h = (s[0]-'0') * 10 + (s[1]-'0');
    int m = (s[3]-'0') * 10 + (s[4]-'0');

    double angleh = h*30 + (double)m/60 * 30;
    double anglem = m * 6; 

    int ans;
    if(angleh > anglem) ans = angleh - anglem;
    else ans = anglem - angleh;

    if(ans > 180) {
      if(angleh > anglem) ans = 360-angleh + anglem;
      else ans = 360-anglem + angleh;
    }

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

C++: #include <iostream>

using namespace std;

int main()
{
	int n;
	float s, t;
	
	cin >> n;
	while(n--){
		scanf("%f:%f", &s, &t);
		
		s = s*30-5.5*t;
		if(180 < s){
			s = 360.0 - s;
		} else if(s < 0){
			s = -s;
		}
		
		if(0 <= s && s < 30){
			cout << "alert" << endl;
		} else if(90 <= s && s <= 180){
			cout << "safe" << endl;
		} else {
			cout << "warning" << endl;
		}
	}
}

C++: // 2011/10/02 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		string str;
		cin >> str;
		str[2] = ' ';

		istringstream is(str);
		int hh, mm;
		is >> hh >> mm;

		double L = mm*6.0;
		double S = hh*30.0+mm/2.0;

		if(L<S){
			double tmp = L;
			L = S;
			S = tmp;
		}

		double A;
		if(L-S>180.0)
			A = (S+360.0)-L;
		else
			A = L-S;

		if(A>=0.0&&A<30)
			cout << "alert" << endl;
		else if(A>=90.0&&A<=180.0)
			cout << "safe" << endl;
		else
			cout << "warning" << endl;
	}

	return 0;
}