#include <iostream>
using namespace std;
bool canbe = false;
string inp;

void dfs(int b, int c, int depth){
    if (depth >= 9){ canbe = true; return; }
    if (inp[depth] - '0' < b && inp[depth] - '0' < c) return;

    if (inp[depth] - '0' > b) dfs(inp[depth] - '0', c, depth+1);
    if (inp[depth] - '0' > c) dfs(b, inp[depth] - '0', depth+1);
}


int n;
int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
	canbe = false;
	inp = "";
	string g;
	for (int j = 0; j < 10; j++){
	    cin >> g;
	    inp += g;	    
	}
	dfs(0, 0, 0);

	if (canbe) cout << "YES" << endl;
	else cout << "NO" << endl;
    }
}