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>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, k;
stack<int> sb, sc;
bool f = 1;

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 10){
			cin >> k;
			if (sb.empty()){
				sb.push(k);
			}
			else if (sc.empty()){
				sc.push(k);
				if (sb.top() < k){
					sc.pop();
					sc.push(sb.top());
					sb.pop();
					sb.push(k);
				}
			}
			else{
				if (sb.top() < k){
					sb.push(k);
				}
				else if (sc.top() < k){
					sc.push(k);
				}
				else{
					f = 0;
				}
			}
		}
		cout << sb.size() << sc.size() << endl;
		if (f){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
		while (!sb.empty()){
			sb.pop();
		}
		while (!sc.empty()){
			sc.pop();
		}
		f = 1;
		cout << sb.size() << sc.size() << endl;
	}
}

C++: /*
* Filename:    aoj0033.cpp
* Desciption:  DFS
* Created:     2016-03-02
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define INT_MAX 2<<30
using namespace std;
//typedef long long ll;
int a[10],n;
int used[10];
bool ans=false;
bool check(){
	int ss=0;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){ss=a[i];break;}
	}
	if(ss==0)return true;
	for (int i = 0; i < 10; i += 1)
	{
		if(used[i]==0){
			if(a[i]<ss)return false;
			else ss=a[i];
		}
	}
	return true;
}
void dfs(int k,int rec){
	if(k==10){
		if(check())ans=true;
		return;
	}
	if(ans)return;
	if(a[k]>rec){
		used[k]=1;
		dfs(k+1,a[k]);
		used[k]=0;
		dfs(k+1,rec);
		if(ans)return;
	}
	else{
		used[k]=0;
		dfs(k+1,rec);
	}
}

int main()
{
	scanf("%d",&n);
	for (int i = 0; i < n; i += 1)
	{
		for (int j = 0; j < 10; j += 1)
		{
			scanf("%d",&a[j]);
		}
		memset(used,0,sizeof(used));
		ans=false;
		used[0]=1;
		dfs(1,a[0]);
		if(ans)printf("YES");
		else printf("NO");
		
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

// to avoid error on mingw
string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int M = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(8);
    ios_base::sync_with_stdio(false);

    int N;
    cin >> N;

    while(N--) {
        int a[10];
        rep(i, 10)
            cin >> a[i];

        bool probEnd = false;
        rep(i, 2<<10) {
            int left = 0, right = 0;
            bool failed = false;

            rep(j,10) {
                bool isRight = ( (i>>j) & 0x1 );
                if(isRight) {
                    if(right > a[j]) {
                        failed = true;
                        break;
                    }
                    right = a[j];
                }
                else {
                    if(left > a[j]) {
                        failed = true;
                        break;
                    }
                    left = a[j];
                }
            }

            if(!failed) {
                cout << "YES" << endl;
                probEnd = true;
                break;
            }
        }

        if(!probEnd)
            cout << "NO" << endl;
    }

    return 0;
}

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