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++: #include<iostream>
using namespace std;
int main(void)
{
    int bo[11],n,B[11],C[11],b1=0,c1=0,A=0,k=0,l=1;
    cin>>n;
    for(int i=0;i<n;i++){
            C[0]=11;k=0;l=0;B[0]=0;b1=0;c1=0;C[1]=13;
        for(int j=0;j<10;j++){
            cin>>bo[j];
        }
        for(int j=1;;j++){
                cout<<bo[j]<<" ";
            if(j==1)B[0]=bo[0];
        if(C[0]==11&&j==2){
            C[0]=bo[j];
            k++;
            //cout<<"6\n";
        }else if(C[1]==13&&j>3&&C[0]<bo[j]){
            C[1]=bo[j];
            k++;
            c1=1;
           // cout<<"7\n";
        }else if(B[l]<bo[j]){
            b1=1;
            B[l+1]=bo[l];
            l++;
           // cout<<"1\n";
        }else if(C[0]==11){
            C[0]=bo[j];
            k++;
            //cout<<"2\n";
        }else if(C[k-1]<bo[j]){
            c1=1;
            C[k+1]=bo[j];
           // cout<<"3\n";
        }else if(B[l]<bo[j+1]){
            C[k+1]=bo[j];
            k++;
           // cout<<"5\n";
        }else{
            B[l+1]=bo[j];
            l++;
          //  cout<<"4\n";
        }
        if(j==9||(b1==1&&c1==1))break;
    }
    if(b1==1&&c1==1)cout<<"YES\n";
    else cout<<"NO\n";
    for(int j=0;j<10;j++){
        B[j]=0;C[j]=0;
    }

}
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  int num1[10];
  for(int i=0;i<n;i++)
    {
      int count=0;
      for(int j=0;j<10;j++)
	{
	  cin>>num1[j];
	}
      for(int k=0;k<10-1;k++)
	{
	  int num2[10];
	  if(num1[k]>num1[k+1])
	    {
	      int l=0;
	      num2[l]=num1[k];
	      l++;
	    }
	  if(num1[k]>num1[k+1] && num2[k]>num2[k+1] && num2[k+1]!=0)count++;
	}
      if(count>0)cout<<"NO"<<endl;
      else cout<<"YES"<<endl;
    }
  return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int t,flag;
	//freopen("C:\\Users\\国民党\\Desktop\\text.txt", "r", stdin);
	cin >> t;
	while (t--)
	{
		flag = 1;
		int a, b = -1, c = -1;
		for (int i = 1; i <= 10; i++)
		{
			cin >> a;
			if (a > b)
			{
				b = a;
			}
			else if (a > c)
			{
				c = a;
			}
			else
				flag = 0;
		}
		cout << ((flag == 1) ? "YES" : "NO" )<< endl;
	}
	return 0;
}

C++: #include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
        int n;
        int b = 0;
        int c = 0;
        int d = 0;
        int A[10] = {};
        int B[10] = {};
        int C[10] = {};
        cin >> n;
        for (int i = 0;i < n;i++) {
                for (int j = 0;j < 10;j++) {
                        cin >> A[j];
                }

                for (int j = 0;j < 10;j++) {
                        if (d == 0) {
                                if (j == 0) {
                                        B[0] = A[0];
                                        b++;
                                }
                                if ((A[j] > B[b]) && (B[b] > C[c])) {
                                        B[b] = A[j];
                                        b++;
                                }
                                if (A[j] > C[c]) {
                                        C[c] = A[j];
                                        c++;
                                }
                                if ((A[j] < B[b - 1]) && (A[j] < C[c - 1])) {
                                        cout << "NO" << endl;
                                        d = 1;
                                }
                        }
                }
                if (d == 0) {
                        cout << "YES" << endl;
                }
                d = 0;
        }
        return 0;
}

C++: #include <cstdio>

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
	if(i == N) return true;
	if(R < Ball[i]) {
		R = Ball[i];
		if( solve(i+1) ) return true;
	}
	if(L < Ball[i]) {
		L = Ball[i];
		if( solve(i+1) ) return true;
	}
	return false;
}

int main() {
	scanf("%d", &D);
	for(int i = 0; i < D; i++) {
		R = L = 0;
		for(int j = 0; j < N; j++) scanf("%d", &Ball[j]);
		R = Ball[0];
		if( solve(1) )	printf("YES\n");
		else			printf("NO\n");
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;



int main(){
	int n;

	cin >> n;
	while(n--){
		int a;
		bool p = true;
		int b = 0, c = 0;
		for(int i = 0; i < 10; i++){
			cin >> a;
			if(p){
				if(a > b){
					b = a;
				}else if(a > c){
					c = a;
				}else{
					p = false;
				}
			}
		}
		
		if(p){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
template<typename V> typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();

// clang-format on

bool dfs(vi v, int l, int r) {
  if (v.size() == 0) {
    return true;
  }
  bool hoge = false;
  if (v.back() > l) {
    vi _v  = v;
    int _l = v.back();
    _v.pop_back();
    hoge |= dfs(_v, _l, r);
  }
  if (v.back() > r) {
    vi _v  = v;
    int _r = v.back();
    _v.pop_back();
    hoge |= dfs(_v, l, _r);
  }
  return hoge;
}

main {
  int n;
  cin >> n;
  rep(_, n) {
    vi v(10);
    rep(i, 10) cin >> v[9 - i];
    cout << (dfs(v, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}