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++: /*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int a[10];

bool dfs(int B, int C, int cnt) {
    if(cnt == 10) return true;

    if(B < a[cnt]){
        return dfs(a[cnt], C, cnt + 1);
    }
    if(C < a[cnt]) {
        return dfs(B, a[cnt], cnt + 1);
    }
    if(B > a[cnt] && C > a[cnt]) {
        return false;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    rep(i, n) {
        rep(j, 10) cin >> a[j];
        if(dfs(0, 0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define range(i,b) rep(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int input;
	bool check;

	while(cin >> n){
		range(i,n){
			a = b = 0;
			range(i,10){
				check = true;
				cin >> input;
				if(input > a && input > b){
					if(a > b)
						a = input;
					else
						b = input;
				}else if(input > a){
					a = input;
				}else if(input > b){
					b = input;
				}else{
					check = false;
				}
			}
			if(check) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>

using namespace std;

int main()
{
	int T;
	cin >> T;
	int a[11];
	bool vis[11];
	while (T--)
	{
		bool flag = 1;
		memset(vis, 0, sizeof(vis));
		for (int i = 1; i <= 10; i++)
			scanf("%d", &a[i]);
		stack<int> s;
		s.push(a[1]);
		vis[1] = 1;
		for (int i = 2; i <= 10; i++)
		{
			if (a[i] > s.top())
			{
				s.push(a[i]);
				vis[i] = 1;
			}
		}
		int temp,i;
		for ( i = 2; i <= 10; i++)
		{
			if (vis[i] == 0)
			{
				temp = a[i];
				break;
			}
		}
		i++;
		for (i; i <= 10; i++)
		{
			if (vis[i] == 0)
			{
				if (a[i] >= temp)
				{
					temp = vis[i];
				}
				else if (a[i] < temp)
				{
					flag = 0;
					break;
				}
			}
		}
		if (flag == 1)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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


int res=0;

int saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return res;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return res;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		for(b=0;b<10;b++){
			ball[b]=0;
		}
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		res=max(res,saiki(ball,ttB,ttC,res));
		if(res==10)printf("Yes\n");else printf("No\n");
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<n;i++)
using namespace std;
int main() {
    int n; cin >> n;
    rep(q, n) {
        vector<int> a(10);
        rep(j, 10) cin >> a[j];
        bool ok = 1;
        rep(j, a.size() - 1) {
            if (a[j] > a[j + 1]) {
                ok = 0;
                break;
            }
        }
        if (ok) {
            cout << "YES" << endl;
            continue;
        }
        req(bit, 1 << 10) {
            if (bit == 1023) {
                cout << "NO" << endl;
                break;
            }
            vector<int> b, c;int cnt = 0;
            rep(j, 10) {
                if (bit & (1 << j)) {
                    cnt++;
                    b.push_back(a[j]);
                }
                else c.push_back(a[j]);
            }
            bool ch = 1,ok=1;
            rep(j, b.size() - 1) {
                if (b[j] > b[j + 1]) {
                    ch = 0;
                    break;
                }
            }rep(j, c.size() - 1) {
                if (c[j] > c[j + 1]) {
                    ok = 0;
                    break;
                }
            }
            if (ok && ch) {
                cout << "YES"  << endl;
                break;
            }
        }
    }
}