Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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