#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf = 0x7f7f7f;
//const int maxn = ;

int main() {
//ios::sync_with_stdio(false);
#ifdef LOCAL
freopen("lll.in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
	int t;
	cin >> t;
	while(t--) {
		int a;
		int lt = -1, rt = -1;
		bool flag = true;
		for(int i = 1; i <= 10; i++) {
			cin >> a;
			if(!flag) continue;
			if(a > lt && a > rt) {
				if(a - lt <= a - rt)
					lt = a;
				else
					rt = a;
			} else if(a > lt && a <= rt) {
				lt = a;
			} else if(a <= lt && a > rt) {
				rt = a;
			} else {
				flag = false;
			}
		}

		if(flag) 
			printf("YES\n");
		else 
			printf("NO\n");
	}
}


