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;
#define rep(i,n) for(int i=0;i<n;i++)
#define B 0
#define C 1

int main()
{
    int n;
    cin >> n;
    while(n>0)
    {
        int a[10],b[10],c[10];
        rep(i,10)cin >> a[i];
        int bnum=0,cnum=0;
        int t;
        int side = B;
        int res =1;
        b[0] =a[9];
        bnum = 1;
        for(int i = 8;i!=0;i--)
        {
            if(side == B)
            {
                if(b[bnum-1]<a[i])
                {
                    side=C;
                    if((cnum!=0)&&(c[cnum]<a[i])){res = 0;break;}
                    else{cnum++; c[cnum]=a[i]; }
                }
                else
                {
                    bnum++;
                    b[bnum] = a[i];
                }
            }
            else
            {
                if(c[cnum-1]<a[i]){
                    side = B;
                    if(b[bnum]<a[i]){res = 0;break;}
                    else{bnum++; b[bnum] = a[i];}
                }
                else
                {
                    cnum++;
                    c[cnum]=a[i];
                }
            }
        }
        if(res==1)cout <<"YES" << endl;
        else cout << "NO" << endl;

        n--;
    }

    return 0;
}

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

int main() {
	int a, n, j;
	cin >> n;
	for (int i = 0; i < n; i++) {
		vector<int> a(10);
		vector<int> b, c;
		for (j = 0; j < 10; ++j) cin >> a[j];
		for (j = 0; j < 11; j++) {
			if (j == 10) {
				break;
			}
			if (j == 0) {
				b.push_back(a[j]);
			}
			else if (a[j] < b[b.size() - 1] && c.size() == 0) {
				c.push_back(a[j]);
			}
			else if (a[j] > b[b.size() - 1]) {
				b.push_back(a[j]);
			}
			else if (a[j] > c[c.size() - 1]) {
				c.push_back(a[j]);
			}
			else {
				break;
			}
		}
		if (j == 10) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}