Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: /*#include<iostream>
#include<stack>
using namespace std;
int source[15];
int main()
{
    int x;
    cin>>x;
    while(x--)
    {
        stack<int>a;
        stack<int>b;
        a.push(0);
        b.push(0);
        for(int k=0;k<10;k++)
            cin>>source[k];
            int i;
            bool flag=0;
        for(i=0;i<10;i++)
        {
            if(source[i]<a.top()&&source[i]<b.top())
               {
                   flag=1;
                    break;
               }
             else if(source[i]>a.top()&&source[i]<b.top())
                    a.push(source[i]);
             else if(source[i]>b.top()&&source[i]<a.top())
                    b.push(source[i]);
                    else
                    {

                    if(a.top()>=b.top())
                        a.push(source[i]);
                    else
                        b.push(source[i]);
                    }
        }
                if(flag)
                cout<<"NO"<<endl;
                else
                    cout<<"YES"<<endl;
    }
    return 0;
}*/
#include<iostream>
using namespace std;
int a[15];
int flag;
void dfs(int x,int l,int r)
{
    if(flag)
        return ;
    if(x==10)
    {
        return ;
    }
    else
    {
        if(a[x]>l)
           dfs(x+1,a[x],r);
        else if(a[x]>r)
            dfs(x+1,l,a[x]);
        else
        {
            flag=1;
            return ;
        }
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        for(int i=0;i<10;i++)
            cin>>a[i];
            flag=0;
            dfs(0,0,0);
            if(flag)
                cout<<"NO"<<endl;
            else
                cout<<"YES"<<endl;
    }
    return 0;
}

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

int main()
{
	int n, ball;
	queue<pair<int, int> > qu;

	cin >> n;

	for (int i=0; i<n; i++){
		bool flag = true;

		cin >> ball;
		qu.push(make_pair(ball, 0));

		for (int j=0; j<9; j++){
			cin >> ball;

			while (ball != qu.front().first && ball != qu.front().second)
			{
				if(qu.front().first < ball){
					qu.push(make_pair(ball, qu.front().second));
					//cout << ball << ',' << qu.front().second << ' ';	//debug
				}
				if(qu.front().second < ball){
					qu.push(make_pair(qu.front().first, ball));
					//cout << qu.front().first << ',' << ball;	//debug
				}

				//cout << endl; //debug
				
				qu.pop();
				if(qu.empty())	break;
			}

			if(qu.empty())	break;

			if(j==8){
				cout << "YES" << endl;
				flag = false;
			}
		}

		if(flag)	cout << "NO" << endl;
		
		while (!qu.empty()) qu.pop();
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <stack>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

void solve33() {
    stack<int> st1;
    stack<int> st2;
    REP(i,10) {
        int j;
        cin >> j;
        if (st1.size() == 0 || st1.top() < j) st1.push(j);
        else if (st2.size() == 0 || st2.top() < j) st2.push(j);
        else break;
        if (i == 9) {cout << "YES" << endl; return;}
    }
    cout << "NO" << endl;
}

int main() {
    int n;
    cin >> n;
    REP(i,n) {
        solve33();
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
	int n; cin >> n;
	int l = 0, r = 0;
	bool ok = true;
	while (n--) {
		rep(i, 10) {
			int b; cin >> b;
			if(l < b) l = b;
			else if (r < b) {
				r = b;
				if (l < r) swap(l, r);
			}
			else {
				ok = false;
			}
		}
		cout << (ok ? "YES" : "NO" ) << endl;
	}
	return 0;
}

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