#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	int N; cin >> N;
	for(int rou = 0; rou < N; rou++) {
		vector<int> data(10);
		rep(i,10) cin >> data[i];
		bool ans = false;
		for(int i = 0; i < (1<<10); i++) {
			vector<int> b;
			vector<int> c;

			rep(j,10) {
				if(i & (1<<j)) {
					b.pb(data[j]);
				} else {
					c.pb(data[j]);
				}
			}

			bool f = true;
			int bp = 0;
			int cp = 0;
			for(int j = 0, n = b.size(); j < n; j++) {
				if(b[j] < bp) f = false;
				bp = b[j];
			}
			for(int j = 0, n = c.size(); j < n; j++) {
				if(c[j] < cp) f = false;
				cp = c[j];
			}
			if(f) {
				ans = true;
				break;
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}