#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.ball", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	int i,j;
	for (i = 0; i < n; ++i){
		vector <int> ball;
		getline (cin, str );
		stringstream ss(str);
		int b;
		while (ss >> b){
			ball.push_back(b);
		} // end while
		stack <int> A;
		stack <int> B;

		A.push (0);
		B.push (0);

		int size = ball.size();

		A.push (ball[0]);
		for (j = 1; j < size; ++j){
//			cout << "ball[" << j << "]: " << ball[j] << endl;
//			cout << "A:" << A.top() << " B: " << B.top() << endl;
			if (ball[j] < A.top() && ball[j] > B.top() ){
//				cout << "B in" << endl;
				B.push (ball[j]);
			}else if (ball[j] > A.top() && ball[j] < B.top() ){
//				cout << "A in" << endl;
				A.push (ball[j]);
			}else if (ball[j] > A.top() && ball[j] > B.top() ){
				if (ball[j] - A.top() < ball[j] - B.top() ){
//					cout << "A in" << endl;
					A.push (ball[j]);
				}else{
//					cout << "B in" << endl;
					B.push (ball[j]);
				} // end if 
			}else{
				cout << "NO" << endl;
				break;
			} // end if
		} // end for
		if (j == size ){
			cout << "YES" << endl;
		} // end if
	} // end for
		
	return 0;
}