#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		bool can = true;
		int left = 0, right = 0;
		rep(j, 10){
			int a;
			scanf("%d", &a);
			if(min(left, right) > a){
				can = false;
			}
			if(max(left, right) < a){
				if(left<right) right = a;
				else left = a;
			}else{
				if(left<right) left = a;
				else right = a;
			}
		}

		puts(can ? "YES" : "NO");
	}

	return 0;
}