Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

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


int main() {
  int n;
  int data[10];
  cin >> n;
  while ( n > 0 ) {
    n--;
    int flag = 1;
    for ( int i = 0; i < 10; i++ ) cin >> data[i];
    int b = data[0],c = data[1];
    for ( int i = 2; i < 10; i++ ) {
      if ( b < data[i] ) b = data[i];
      else if ( c < data[i] ) c = data[i];
      else flag = 0;
    }
    if ( flag ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int n;
int ba[10];

bool all(int,int,int);

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ba[j];
    }
    if(all(0,0,0)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

bool all(int end,int l,int r){
  if(end==10){
    return true;
  }else if(ba[end]>l){
    return all(end+1,ba[end],r);
  }else if(ba[end]>r){
    return all(end+1,l,ba[end]);
  }
  return false;
}

C++: #include <iostream>
#include <vector>
using namespace std;
bool separate(int* A, int i, vector<int>& vB, vector<int>& vC)
{
	if (i == 10)
		return true;
	
	{
		vector<int> vTmpB(vB);
		if (vTmpB.empty() || (!vTmpB.empty() && (vTmpB.back() < A[i]))){
			vTmpB.push_back(A[i]);
			if (separate(A, i + 1, vTmpB, vC))
				return true;
		}
	}

	{
		vector<int> vTmpC(vC);
		if (vTmpC.empty() || (!vTmpC.empty() && (vTmpC.back() < A[i]))){
			vTmpC.push_back(A[i]);
			if (separate(A, i + 1, vB, vTmpC))
				return true;
		}
	}

	return false;
}
int main()
{
	int n;
	cin >> n;
	int A[10] = {};
	while(n--){
		for (int j = 0; j < 10; ++j)
			cin >> A[j];
		vector<int> vB, vC;
		if (separate(A, 0, vB, vC)) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}

C++: a[10];int dfs(int l,int r,int i){if(i>9)return 1;if(a[i]>l&&dfs(a[i],r,i+1))return 1;if(a[i]>r&&dfs(l,a[i],i+1))return 1;return 0;
}main(n){scanf("%d",&n);for(;n;n--)scanf("%d%d%d%d%d%d%d%d%d%d",a+0,a+1,a+2,a+3,a+4,a+5,a+6,a+7,a+8,a+9),dfs(0,0,0)?puts("YES"):puts("NO");return 0;}

C++: #include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int bmax[10],cmax[10];
int main() {
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        int ball[10]={};
        int ans=0;
        for(int j=0; j<10; j++){
            cin>>ball[j];
        }
        for(int s=2; s<10; s++){
            for(int t=0; t<s; t++){
                if(ball[s]>ball[t]){
                    ans++;
                    break;
                }
            }
        }
        if(ans==8) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int n;
int a[15],b[15],c[15];
int flag;
void dfs(int i,int j,int x)
{
    if(i + j == 12){
        flag = 1;
        return ;
    }
    if(flag == 1)
        return ;
    if(a[x] > b[i - 1]){
        b[i] = a[x];
        dfs(i + 1,j,x + 1);
    }
    else
    {
        if(a[x] > c[j - 1]){
            c[j] = a[x];
            dfs(i,j + 1,x + 1);
        }
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        while(n --){
            for(int i = 0; i < 10; i++)
                scanf("%d",&a[i]);
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            flag = 0;
            dfs(1,1,0);
            if(flag == 1)
                printf("YES\n");
            else
                printf("NO\n");
            /*for(int i = 0; i < 10; i++)
                printf("%d",b[i]);
            //printf("\n\n\n\n");
            /*for(int i = 0; i < 10; i++)
                printf("%d",c[i]);
            printf("\n");*/

        }
    }
    return 0;
}

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;
}