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>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int t,n=10,a[10002],b[10002],c[10002];
bool flag;

void dfs(int dep,int db,int dc)
{
	if(!flag)return;
	if(dep==n)
	{
		flag=0;
		for(int i=1;i<db;++i)
			if(b[i]<b[i-1])
				flag=1;
		for(int i=1;i<dc;++i)
			if(c[i]<c[i-1])
				flag=1;
		return;
	}
	b[db]=a[dep];
	dfs(dep+1,db+1,dc);
	c[dc]=a[dep];
	dfs(dep+1,db,dc+1);
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		flag=1;
		for(int i=0;i<n;++i)
			scanf("%d",&a[i]);
		dfs(0,0,0);
		if(flag)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

C++: #include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        int i,j,k,l;
        int f=1;
        j=-0x3f3f3f;
        k=-0x3f3f3f;
        for(i=2;i<10;i++){
            scanf("%d",&l);
            if(f)
            {
                if(j<l){
                    j=l;
                }
                else
                if(k<l){
                    k=l;
                }
                else{
                    f=0;
                }

            }


        }
        if(f){
            printf("YES\n");

        }
        else
            printf("NO\n");

    }





    return 0;
}

C++: #include <iostream>

using namespace std;

int ball[10],f;

int hukasa(int cup1,int cup2,int no){
	//cout << "NOW no:" << no << endl;
	if(no>=10)return 1;
	else if((ball[no]<cup1)&&(ball[no]<cup2))return 0;
	
	if(cup1<ball[no])return hukasa(ball[no],cup2,no+1);
	if(cup2<ball[no])return hukasa(cup1,ball[no],no+1);
}
int main(){
	int n;
	cin>>n;
	while(n!=0){
		f = 0;
		for(int i=0;i<10;i++){
			cin>>ball[i];
			}
		f = hukasa(0,0,0);
		//cout << "f is " << f << endl;
		if(f==1)cout << "YES" << endl;
		else cout<<"NO"<<endl;
		n-=1;
}
}

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

int main() {
	int n, x;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector<vector<int>> v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < v.size(); k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == v.size() - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}
		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#define MAX_BALL 10
using namespace std;

int ball[MAX_BALL];
int n;
int r = 0, l = 0;
bool flag = 0;

void dfs(int x)
{
	if (x == MAX_BALL)
	{
		flag = true;
		return;
	}
	if (ball[x] >= r)
	{
		r = ball[x];
		dfs(x + 1);
	}
	if (ball[x] >= l)
	{
		l = ball[x];
		dfs(x + 1);
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		flag = false;
		r = 0;
		l = 0;
		for (int j = 0; j < MAX_BALL; j++)
			cin >> ball[j];
		dfs(0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

C++: #include <cstdio>

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
	if(i == N) return true;
	if(R < Ball[i]) {
		R = Ball[i];
		if( solve(i+1) ) return true;
	}
	if(L < Ball[i]) {
		L = Ball[i];
		if( solve(i+1) ) return true;
	}
	return false;
}

int main() {
	scanf("%d", D);
	for(int i = 0; i < D; i++) {
		R = L = 0;
		for(int j = 0; j < N; j++) scanf("%d", &Ball[j]);
		R = Ball[0];
		if( solve(1) )	printf("YES\n");
		else			printf("NO\n");
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>

using namespace std;

int N;
const int LEN = 10;
int arr[LEN+1];
vector<int> bucket[2];

bool dfs(int n, int idx)
{
    if (n == LEN)
        return true;
    vector<int>& buc = bucket[idx];
    if (!buc.empty() && arr[n] < buc.back()) return false;
    buc.push_back(arr[n]);
    bool res[2];
    res[0] = dfs(n+1, 0);
    if (res[0]) goto finish;
    res[1] = dfs(n+1, 1);
finish:
    buc.erase(buc.end()-1);
    return res[0] || res[1];
}

int main()
{
    scanf("%d", &N);
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < LEN; i++) {
            scanf("%d", &arr[i]);
        }
        if (dfs(0, 0) || dfs(0, 1)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int ball;
	int n;
	while(cin >> n){
		bool flag = true;
		for(int i=0; i<n; i++){
			int B=0, C=0;
			for(int j=0; j<10; j++){
				cin >> ball;
				if(flag){
					if(B < ball) B=ball;
					else if(C < ball) C=ball;
					else flag=false;
				}
			}
			
			if(flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<math.h>
#include<string>
#include<stack>
#include<typeinfo>
using namespace std;
typedef pair<int, int> P;
int main() {
	int n,ball[10],under;
	cin >> n;
	for (int data = 0; data < n; ++data) {
		for (int i = 0; i < 10; ++i) cin >> ball[i];
		under = ball[0];
		ball[0] = 0;
		for (int i = 1; i < 10; ++i) {
			if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
		}
		int k;
		for (k = 1; k < 10; ++k) {
			if (ball[k] == 0)continue;
			else {
				under = ball[k];
				ball[k] = 0;
				break;
			}
		}
		char bo = true;
		for (int i = k + 1; i < 10; ++i) {
			if (ball[i] == 0)continue;
			else if (under < ball[i]) {
				under = ball[i];
				ball[i] = 0;
			}
			else {
				bo = false;
				break;
			}
		}
		if (bo)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	cin>>n;
	while (n--){
	bool yes=true;
		stack<int> s1;
		stack<int> s2;
		s1.push(0);
		s2.push(0);
		REP(i, 10){
			int a;
			cin >> a;
			if (s1.top() <= s2.top()){
				if (s1.top() < a)
					s1.push(a);
					continue;
			}
			if (s2.top() < a){
					s2.push(a);
					continue;
			}
			yes=false;

		}
		if (yes)
			cout << "YES"<<endl;
			else
				cout << "NO" << endl;
	}
	return 0;
}