#include <iostream>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,a[10],b,c;
	cin >> n;
	rep(kk, n){
		rep(i, 10)
			cin >> a[i];
			b = c = 0;
		rep(i, 10){
			if (a[i] > b && b >= c){ b = a[i]; cout << "B:" << b; }
			else if (a[i] > c){ c = a[i]; cout << "A:" << c; }
			else { cout << "NO" << endl; break; }
			if (i == 9){ cout << "YES" << endl; break; }
		}
	}
}
