Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] == 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  len[0] = len[1] = 0;
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
int dfs(int w,int h,int noww,int nowh,int n,int b){
	++n;
	if(noww>w || nowh>h) return 0;
	if(noww==w && nowh==h) return 1;
	int ret=0;
	for(int i=0; i<2; ++i){
		if(n>=2){
			n=0;
			if(i==0){
				b=1;
				ret+=dfs(w,h,++noww,nowh,n,b);
			} else if(i==1){
				b=2;
				ret+=dfs(w,h,noww,++nowh,n,b);
			}
		} else{
			if(b==1)ret+=dfs(w,h,++noww,nowh,n,b);
			if(b==2)ret+=dfs(w,h,noww,++nowh,n,b);
		}
	}
	return ret;
}

int main()u{
	int w,h;
	cin >> w >> h;
	cout << dfs(w,h,1,1,2,0) << endl;
	return 0;
}
*/
int calc(vector<int> balls,int i,int cas1,int cas2,int a,int sum);

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; ++i){
		vector<int> balls(10);
		for(int i=0 ;i<10; ++i){
			cin >> balls[i];
		}
		int sum=0;
		if(calc(balls,0,0,0,0,sum)>0){
			cout << "YES" << endl;
		} else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

int calc(vector<int> balls,int i,int cas1,int cas2,int a,int sum){
	if(i==10) {
		//cout << cas1 << " " << cas2 << " " << a << " " << balls[i-1] << endl;
		return 1;
	}
	if(a==0&&balls[i]<cas1) return 0;
	if(a==1&&balls[i]<cas2) return 0;
	if(a==0)cas1=balls[i];
	if(a==1)cas2=balls[i];
	sum += calc(balls,i+1,cas1,cas2,0,sum);
	sum += calc(balls,i+1,cas1,cas2,1,sum);

	return sum;
}

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

#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)

int main(){
    int n;
    cin >> n;
    REP(i,n){
        int a, p1 = 0, p2 = 0;
        bool flag = true;
        REP(j,10){
            cin >> a;
            if(p1 >= p2 && p1 < a){
                p1 = a;
            } else if(p2 < a){
                p2 = a;
            } else {
                flag = false; break;
            }
        }
        cout << (flag?"YES":"NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
#define CAPACITY 9
using namespace std;
int b, c;

bool dfs(int pos, int ary[], bool flag) {
    if(pos < 0) {
        return(false);
    }
    
    flag = dfs(pos - 1, ary, flag);
    
    if(pos == CAPACITY) {
        flag = true;
    }
    if(ary[pos] > b) {
        b = ary[pos];
    } else if(ary[pos] > c) {
        c = ary[pos];
    } else {
        return(false);
    }
    cout << "B = " << b << "C = " << c << endl;
    
    return(flag);
}

int main(void) {
    int num;
    
    cin >> num;
    int ary[10];
    
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            cin >> ary[c];
        }
        b = ary[0];
        c = INT_MIN;
        if(dfs(CAPACITY, ary, true)) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << endl;
    }
    
    return(0);
}

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

int main(void){
  int N,temp,flag;
  vector<int> A,B(1,0),C(1,0);
  cin >> N;
  for(int i=0; i<N; ++i){
    while(!A.empty()){
      for(int j=0; j<10; ++j){
	cin >> temp;
	A.push_back(temp);
      }
      temp = A.front();
      if(temp>=*B.end()) B.push_back(temp);
      if(temp>=*C.end()) C.push_back(temp);
      else{
	cout << "NO" << endl;
	flag = 1;
	break;
      }
      A.pop_back();
    }
    if(flag!=1)
      cout << "YES" << endl;
    flag=0;
  }
}

C++: #include<iostream>
#include<vector>
using namespace std;
bool a[15]; 
int d[15];
vector<int> b,c;
int judge; 
void dfs(int n){
	if(n==10){
		for(int i=0;i<10;i++){
			if(a[i]==false){//进c 
				c.push_back(d[i]);
			}
			else{
				b.push_back(d[i]);
			}
		}
		int ok=1;
		for(int j=0;j<b.size()-1;j++){
			if(b[j]>b[j+1]){
				ok=0;
				break;
			}
		}
		for(int j=0;j<c.size()-1;j++){
			if(c[j]>c[j+1]){
				ok=0;
				break;
			}
		}
		if(ok)judge=1;
	}
	else{
		a[n]=true;
		dfs(n+1);
		a[n]=false;
		dfs(n+1);
	}
}
int main(){
	int n;
	cin>>n;
	while(n--){
		b.clear();c.clear(); 
		judge=0;
		for(int i=0;i<10;i++){
			cin>>d[i];
		}
		dfs(0);
		if(judge){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	int ball[10];
	int cell[2][10]={0};
	int n,i,k,cell_1=0,cell_2=0,flag[1000]={0};
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
		for(i=0;i<10;i++)scanf("%d",&ball[i]);
		
		cell[0][0]=0;
		cell[1][0]=0;

		for(i=0;i<10;i++){
			if(cell[0][cell_1-1] < ball[i]){
				cell[0][cell_1]=ball[i];
				cell_1++;
			}
			else if(cell[1][cell_2-1] < ball[i]){
				cell[1][cell_2]=ball[i];
				cell_2++;
			}
			else flag[k]=1;
		}	
	}
	
	cell_1=0;
	cell_2=0;
	
	for(i=0;i<n;i++){
		if(flag[i]==0)printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	for(int x=0;x<n;x++){
		bool flag=true;
		int a,b=0,c=0;
		for(int i=0;i<10;i++){
			cin >> a;
			for(int j=a-1;j>=0;j--){
				if(b==j){
					b=a;
					break;
				}
				if(c==j){
					c=a;
					break;
				}
				if(j==0){
					flag = false;
					break;
				}
			}
		}
		if(flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int j,int k){
	if(k==10||(i<a[k]&&dfs(a[k],j,k+1))||(j<a[k]&&dfs(i,a[k],k+1)))return true;
	return false;
}
int main() {
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++)cin>>a[j];
		cout<<(dfs(0,0,0)?"YES":"NO");
	}
	return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

bool flag = false;
int a, b;
vector<int> Vec(10);

void dfs(int pos)
{
	if(pos >= 10)
	{
		flag = true;
		return;
	}
	if(Vec[pos] > a)
	{
		a = Vec[pos];
		dfs(pos + 1);
	}
	if(Vec[pos] > b)
	{
		b = Vec[pos];
		dfs(pos + 1);
	}
}

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		a = 0;
		b = 0;
		flag = false;
		for(int i = 0; i < 10; ++i)
		{
			cin >> Vec[i];
		}
		dfs(0);
		if(flag)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}