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 <iostream>
using namespace std;

int main(){
	int n,ball,tp[2],con,bad;
	
	cin >> n;
	
	for(; n > 0; n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				bad = 1;
			}
		}
		
		if(bad){
			cout << "NO" << endl;
			bad = 0;
		}else{
			cout << "YES" << 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;
}

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

#define NUM 10

bool rec( queue< int >, int, int );

int main() {
	int n;
	cin >> n;
	while( n-- ) {
		int in[ NUM ];
		queue< int > que;
		for( int i = 0; i < NUM; ++i ) { cin >> in[ i ]; }
		for( int i = 0; i < NUM; ++i ) { que.push( in[ i ] ); }

		if( rec( que, 0, 0 ) ) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}
	return 0;
}

bool rec( queue< int > que, int topL, int topR ) {
	if( que.empty() ) { return true; }
	int n = que.front();  que.pop();
	if( ( n > topL && rec( que, n, topR ) ) || ( n > topR && rec( que, topL, n ) ) ) { return true; }
	return false;
}

C++: #include<cstdio>
#include<iostream>
int mitaball(int n,int Bn,int Cn);
int ball[10],B[10]={0},C[10]={0};
int judge;
int a;
int x;
int main(){
    scanf("%d",&x);
    for(int j=0;j<x;j++){
        judge=0;
        for(int i=0;i<10;i++)
            scanf("%d",&ball[i]);
        mitaball(0,0,0);
        if(judge==1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
int mitaball(int n,int Bn,int Cn){
    /*
    if(judge==0){
        if(n==10){
                                for(int k=0;k<10;k++)
                    printf("[%d][%d]\n",B[k],C[k]);
            for(int i=0;i<Bn-1;i++){
                if(B[i]>B[i+1])
                    break;
                judge=1;
            }
            for(int i=0;i<Cn-1;i++){
                if(C[i]>C[i+1]||judge==0){
                    judge=0;
                    break;
                }
                judge=1;
            }
        }
        else{
    */      if(n==10)
                judge=1;
            if(judge==0)
                if(Bn==0||B[Bn-1]<ball[n]){
                    B[Bn]=ball[n];
                        mitaball(n+1,Bn+1,Cn);
                    B[Bn]=0;
                }
                if(Cn==0||C[Cn-1]<ball[n]){
                C[Cn]=ball[n];
                    mitaball(n+1,Bn,Cn+1);
                C[Cn]=0;
            }
    /*
        }
    }
    */
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int main(){
  int n;
  int ball;
  int b, c;
  bool ans;
  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      b = 0; c = 0;ans = true;
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball;
          if (b < ball)
            {
              b = ball;
            }
          else if (c < ball)
            {
              c = ball;
            }
          else
            {
              ans = false;
              // cout << "NO" << endl;
              break;
            }
        }
      cout << (ans ? "YES" : "NO") << endl;
    }
  return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100010;
int t,l[15],r[15],a[10];
bool dfs(int i,int x,int y){
	if(i==11)return true;
	if(a[i]>l[x]){
		l[x+1]=a[i];
		if(dfs(i+1,x+1,y))return true;
		else return false;
	}
	if(a[i]>r[y]){
		r[y+1]=a[i];
		if(dfs(i+1,x,y+1))return true;
		else return false;
	}
	return false;
}
int main()
{
	cin>>t;
	while(t--){
		memset(l,0,sizeof(l));
		memset(r,0,sizeof(r));
		for(int i=1;i<=10;i++)cin>>a[i];
		if(dfs(1,0,0))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <cstdio>

int a[13];


int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    bool ans = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a[i]);
    }
    int l, r;
    l = r = 0;
    for (int i = 0; i < 10; ++i) {
      if (a[i] > l) {
        l = a[i];
      } else if (a[i] > r) {
        r = a[i];
      } else {
        ans = false;
        break;
      }
    }
    printf("%s\n", ans ? "YES" : "NO");
  }
  return 1;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;


int a[10];
int n;

bool dfs(int i,int left, int right){
    if(i==10) return true;
    if(a[i]>left){
        return dfs(i+1,a[i],right);
    }
    if(a[i]>right){
        return dfs(i+1,left,a[i]);
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return;
}

int main(){
    cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}