#include <cstdio>
#include <queue>
using namespace std;

int main(void)
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		queue <int> a;
		int tmp, b = 0, c = 0;
		for (int i = 0; i < 10; i++){
			scanf("%d", &tmp);
			a.push(tmp);
		}
		
		while (1){
			tmp = a.front();
			if (b < tmp) {
				b = tmp;
				a.pop();
			}
			else if (c < tmp) {
				c = tmp;
				a.pop();
			}
			else break;
		}
		
		if (a.empty()) puts("YES");
		else puts("NO");
	}
	
	return (0);
}