#include <iostream>
#include <stack>

using namespace std;

int main() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			int k = A[j];
			if (B.empty() != true && C.empty() != true) {
				if (B.top() > k && C.top() > k) {
					ans = "NO";
					break;
				}
			}
			else if (B.empty() == true)
				B.push(k);
			else if (B.top() < k)
				B.push(k);
			else if (B.top() > k)
				C.push(k);
		}
		cout << ans << endl;
	}
	return 0;
}