Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: ///////////////////////////////////////////////////////////
//どんな人生を選ぶかより、選んだ人生をどう生きるかが大切だ//
/////////////////////////////////////////////////////////
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int MAXN = 105;
int num[15]; bool flag;
void DFS(int index,int maxB, char maxC)
{
	if (index == 10)
	{
		flag = true;
		return;
	}
	if (flag)
	{
		return;
	}
	if (num[index] > maxB)
	{
		DFS(index + 1, num[index], maxC);
	}
	if (num[index] > maxC)
	{
		DFS(index + 1, maxB,num[index]);
	}
}
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		flag = false;
		for (int i = 0; i < 10; i++)
		{
			scanf("%d", &num[i]);
		}
		DFS(0, 0, 0);
		if (flag)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v = { {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main()
{
  int i,j;
  int n,N;
  int b=0,c=0;
  char *str="YES";
  scanf("%d",&N);
  for(i=0;i<N;i++)
    {
      for(j=0;j<10;j++)
	{
	  scanf("%d",&n);
	  if(n>b)
	    b=n;
	  else if(n>c)
	    c=n;
	  else
	    str="NO";
	}
      puts(str);
    }
  
  return 0;
}

C++: #include<iostream>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
 for(B=C=f=i=0;i<10;i++){
  std::cin>>A;
  if(B<A)B=A;
  else if(C<A) C=A;
  else f=1;
 }
}

C++: #include <iostream>
using namespace std;

int n;
int a[10];
int r, l;

bool dfs(int i) {
    if (i == 9) return a[i] > r || a[i] > l;
    if (a[i] > r) {
        r = a[i];
    }
    if (a[i] >l) {
        l = a[i];
    }
    if (dfs(i+1)) return true;
    return false;
}

void solve() {
    if (dfs(0)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> a[j];
        }
        solve();
    }
}

C++: #include <iostream>
using namespace std;

int main() {
int a[10],b[11],c[11];
int n;
cin>>n;
for (int jjj=1;jjj<=n;jjj++){
	for(int kk=0;kk<10;kk++) cin>>a[kk];
int bb=0,cc=0;
b[0]=0;
c[0]=0;
for (int k=0;k<10;k++){
	if(a[k]>b[bb] && b[bb]>=c[cc]){
		b[bb+1]=a[k];
		bb=bb+1;
	}
	else{
		c[cc+1]=a[k];
		cc=cc+1;
	}
}
	int l=0,m=0;
	for(int i=1;i<bb;i++){
		if(b[i]-b[i-1]<0){
			l=2;
		}
	}
	for(int j=1;j<cc;j++){
		if(c[j]-c[j-1]<0){
			m=2;
		}
	}
	if(l+m==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	
}

	return 0;
}

C++: #include <cstdio>
int ball[10];
bool dfs(int n,int b,int c) {
	if(n==10) {
		return true;
	}
	bool res=false;
	if(b<ball[n]) {
		res|=dfs(n+1,ball[n],c);
	}
	if(c<ball[n]) {
		res|=dfs(n+1,c,ball[n]);
	}
	return res;
}
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		for(int j=0;j<10;j++) {
			scanf("%d",&ball[j]);
		}
		printf("%s\n",dfs(0,0,0)?"YES":"NO");
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k, b = 0, c = 0;
bool f = 1;
stack<int> sb, sc;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (b == 0){
				sb.push(k);
				b++;
			}
			else if (c == 0){
				sc.push(k);
				c++;
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
			}
		}
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
	}
}

C++: #define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main(){
	int n;
	int left, right;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> left;
		right=0;
		int temp;
		bool flag = 1;
		//while(cin >> temp){
		for(int j=1;j<10;j++){
			cin >> temp;
			if(left<right){
				if(right<temp){
					right=temp;
				}else if(left<temp){
					left=temp;
				}else{
					flag=false;
				}
			}else{
				if(left<temp){
					left=temp;
				}else if(right<temp){
					right=temp;
				}else{
					flag=false;
				}
			}
		}
		if(flag){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0; lop < n; lop++) {
		int a = 0, b = 0;
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x && b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		if (f)
			cout << "YES\n";
		else
			cout << "NO\n";
		//cout << (f ? "YES\n" : "NO\n");
	}
	return 0;
}

C++: #include<stdio.h>
int n, a[10];
int b[11] = { }, c[11] =

{
};

bool
dfs (int l, int r)
{
  if (l + r == 9)
    return true;
  if (b[l] < a[l + r])
    {
      b[l + 1] = a[l + r];
      return dfs (l + 1, r);
    }
  else if (c[r] < a[l + r])
    {
      c[r + 1] = a[l + r];
      return dfs (l, r + 1);
    }
  return false;
}

int
main (void)
{
  scanf ("%d", &n);
  for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < 10; j++)
	scanf ("%d", &a[j]);
      if (dfs (0, 0))
	puts ("YES");
      else
	puts ("NO");
    }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct P
{
	int x, y;
	P(int x,int y):x(x),y(y){}
	P() :P(-1, -1) {}
};

int A[10];
int N;

bool solve()
{
	vector<int> va, vb;
	va.push_back(0), vb.push_back(0);
	rep(i, 0, 10)
	{
		if (va.back() < A[i])
		{
			va.push_back(A[i]);
		}
		else if (vb.back() < A[i])
		{
			vb.push_back(A[i]);
		}
		else
		{
			return false;
		}
	}
	return true;
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	rep(i, 0, N)
	{
		rep(j, 0, 10)
		{
			cin >> A[j];
		}
		cout << (solve() ? "YES" : "NO") << endl;
	}

	return 0;
}