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

int boll[15];
int dig[2];

bool dfs(int d)
{
    if(d==10) return true;
    int tmp;
    for(int i=0; i<2; ++i)
    {
        if(boll[d]>dig[i])
        {
            tmp = dig[i];
            dig[i] = boll[d];
            if(dfs(d+1)) return true;
            dig[i] = tmp;
        }
    }
    return false;
}

void solve()
{
    dig[0] = dig[1] = -1;
    bool ans = dfs(0);
    printf("%s\n", ans?"YES":"NO");
}

int main()
{
    int n;
    scanf("%d\n", &n);
    while(n--)
    {
        for(int i=0; i<10; ++i) scanf("%d", &boll[i]);
        solve();
    }
    return 0;
}

C++: #include<cstdio>

int ball[11], B[11], C[11];
int cnt1, cnt2;
bool flagb, flagc, flag;

void dfs(int cur) {
    if (flag)return;
    if (cur ==10) {
        flagb = 1, flagc = 1;
        if (cnt1 > 1) {
            for (int i = 0; i < cnt1 - 1; i++)
                if (B[i] > B[i + 1]) {
                    flagb = 0;
                    break;
                }
        }
        if (cnt2 > 1) {
            for (int i = 0; i < cnt2 - 1; i++)
                if (C[i] > C[i + 1]) {
                    flagc = 0;
                    break;
                }
        }

        if (flagb && flagc) {
            flag = 1;
            return;
        }
        return;
    }
    B[cnt1++] = ball[cur];
    dfs(cur + 1);
    cnt1--;
    C[cnt2++] = ball[cur];
    dfs(cur + 1);
    cnt2--;
}

void solve() {
    flag = 0;
    dfs(0);
    if (flag)printf("YES\n");
    else printf("NO\n");
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        cnt1 = 0, cnt2 = 0;
        for (int i = 0; i < 10; i++)
            scanf("%d", &ball[i]);
        solve();
    }
    return 0;
}

C++: #include <stdio.h>

#include <stack>

int main(void){
    using namespace std;
    stack<int> a,b;
    int n,j,i,ball,flag;
    scanf("%d",&n);
    for(j=0; j<n; j++){
        flag=0;
        for(i=0; i<10; i++){
            scanf("%d",&ball);
            if(a.empty()){
                a.push(ball);
            }else if(a.top() < ball){
                a.push(ball);
            }else if(b.empty()){
                b.push(ball);
            }else if(b.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int N;
int num[10];
int lnum,rnum;
bool dfs(int n){
	if(n==10) return true;
	if((num[n]<lnum)&&(num[n]<rnum)) return false;
	else{
		if((num[n]>=lnum)&&(num[n]<rnum)){
			lnum=num[n];
			if(dfs(n+1)) return true;
		}
		if((num[n]>=rnum)&&(num[n]<lnum)){
			rnum=num[n];
			if(dfs(n+1)) return true;
		}
		else{
			int temp=lnum;
			lnum=num[n];
			if(dfs(n+1)) return true;
			else{
				lnum=temp;
				rnum=num[n];
				if(dfs(n+1)) return true;
			}
		}
	}
	return false;
}
void solve(){
	cin>>N;
	for(int i=0;i<N;i++)
	{
	    for(int j=0;j<10;j++)
	    cin>>num[j];
	    if(dfs(0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
int main(){
	solve();
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  int N;
  cin >> N;
  int boll[10];
  for(int i=0;i<10;i++) cin >> boll[i];
  stack<int> B,C;
  B.push(0); C.push(0);
  for(int i=0;i<N;i++){
    for(int j=0;j<10;j++){
      if(B.top()>=C.top()){
        if(boll[j]>B.top()) B.push(boll[j]);
        else if(boll[j]>C.top()) C.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
      } else {
        if(boll[j]>C.top()) C.push(boll[j]);
        else if(boll[j]>B.top()) B.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
      }
      if(j==9) cout << "YES" << endl;
    }
  }
  return 0;
}

C++: #include <iostream>

int ball[10];
bool ans;

void solve();

void dfs(int i, int right, int left);

int main(){
    int n;
    std::cin >> n;
    
    while(n--){
        for(int i = 0; i < 10; ++i)
            std::cin >> ball[i];
        solve();
        if(ans)
            std::cout << "YES" << std::endl;
        else
            std::cout << "NO" << std::endl;
    }
    
    return 0;
}

void solve(){
    ans = false;
    dfs(0, 0, 0);
    return;
}

void dfs(int i, int right, int left){
    if(i == 10){
        ans = true;
        return;
    }
    
    if(ball[i] < right && ball[i] < left)
        return;
    
    if(ball[i] > right)
        dfs(i + 1, ball[i], left);
    else
        dfs(i + 1, right, ball[i]);
    
    if(ans)
        return;
    
    return;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int main(){
    int n; cin >> n;
    while(n--){
        int v[10];
        rep(i,10) cin >> v[i];
        bool ok = false;
        rep(mask,1<<10){
            int a=-1, b=-1;
            bool f = true;
            rep(i,10){
                if(mask>>i & 1){
                    if(a==-1 || a < v[i]) a = v[i];
                    else f = false;
                } else {
                    if(b==-1 || b < v[i]) b = v[i];
                    else f = false;
                }
            }
            if(f){
                ok = true;
                break;
            }
        }
        puts(ok ? "YES" : "NO");
    }
}