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 <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int ball[12];
int n;

bool dfs(int i,int b,int c){
    if(i==11) return true;
    if(ball[i]>b){
        if(dfs(i+1,ball[i],c)) return true;
    }
    if(ball[i]>c){
        if(dfs(i+1,b,ball[i])) return true;
    }
    return false;
}

void solve(){
    int l=0,r=0;
    for(int i=1;i<=10;i++){
        if(ball[i]>l&&ball[i]>r){
            if(l>r) l=ball[i];
            else r=ball[i];
        }
        else{
            if(ball[i]<l&&ball[i]<r){
                printf("NO\n"); return;
            }
            else{
                if(ball[i]>r) r=ball[i];
                else l=ball[i];
            }

        }
    }
    printf("YES\n");
}


int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=10;j++)
            scanf("%d",&ball[j]);
        solve();
    }
    return 0;
}

C++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
int in[10];
bool dfs(int n,vector<int> l,vector<int> r){
  if(n==10)return true;
  if(l.size()==0 or in[n]>l[l.size()-1]) 
  {
    l.push_back(in[n]);
    return dfs(n+1,l,r);
  }
  if(r.size()==0 or in[n]>r[r.size()-1] ){
    r.push_back(in[n]);
    return dfs(n+1,l,r);
  }
  return false;
  }
int main(){
  int d;
  cin>>d;
  for(int dd=0;dd<d;dd++){
    for(int i=0;i<10;i++){
      cin>>in[i];
    }
    vector<int> l,r;
    if(dfs(0,l,r )) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
  
  }
  return 0;
}

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

int main() {
	int n;
	int a;
	vector<int>d;
	vector<int>va = {};
	vector<int>vb = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a;
			d.push_back(a);
		}
		va.push_back(d[0]);		

		for (int j = 1; j < 10; j++) {
			int b = va.size();
			int c = vb.size();

			if (d[j] > va[b-1]) {
				va.push_back(d[j]);
			}
			else if (d[j] > vb[c-1]) {
				vb.push_back(d[j]);
			}
			else {
				cout << "NO" << endl; 
				goto FINLOOP;
			}
		}
		cout << "YES" << endl;
			FINLOOP:
		;
	}
	return 0;
}

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

int main(){

int N,x,y,n;

scanf("%d",&N);

for(int i=0;i<N;i++){
x=n=0;
y=-1;
	for(int j=0;j<10;j++){
		scanf("%d",&n);
		if(x>n && y>n){
			printf("NO\n");
			break;
		}
		else if((x>n && n>y)||(n>y && y>x))
			y=n;
		else if((y>n && n>x)||(n>x && x>y))
			x=n;
		if(j==9)
			printf("YES\n");
	}			
}
return 0;
}

C++: #include <iostream>
#include <array>
#include <vector>

using namespace std;



int main()
{
        int num = 0, tmp_right, tmp_left, ispush = 0, i, j;
        std::array< int, 10 > ar;
        std::vector< int > right, left;
        cin >> num;

        for ( j = 0 ; j < num ; j = j + 1 )
        {
                for ( i = 0 ; i < 10 ; i = i + 1 )
                {
                        cin >> ar[i];
                        ispush = 0;
                        if ( right.size() == 0 )
                        {
                                ispush = 1;
                                right.push_back( ar[i] );
                        }
                        else if ( right.size() != 0 )
                        {
                                tmp_right = right.back();
                                if ( tmp_right < ar[i] )
                                {
                                        right.push_back( ar[i] );
                                        ispush = 1;
                                }
                        }

                        if ( ispush == 0 )
                        {
                                if ( left.size() == 0 )
                                {
                                        ispush = 1;
                                        left.push_back( ar[i] );
                                }
                                else if ( left.size() != 0 )
                                {
                                        tmp_left = left.back();
                                        if ( tmp_left < ar[i] )
                                        {
                                                ispush = 1;
                                                left.push_back( ar[i] );
                                        }
                                }
                        }

                        if ( ispush == 0 )
                        {
                                cout << "NO" << endl;
                                break;
                        }
                        else
                        {
                                ispush = 0;
                        }
//                      cout << i << endl;
                        if ( i == 9 )
                        {
                                cout << "YES" << endl;
                        }


                }
                right.clear();
                left.clear();

        }


        return 0;
}

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

int main()
{
    int Atop, Btop, n, ball;
    cin >> n;
    while (n-->0) {
        Atop=0;
        Btop=0;
        bool fine = true;
        for (int i = 0; i < 10; ++i) {
            cin >> ball;
            if (max(Atop, Btop) < ball) {
                if (Atop >= Btop) Atop = ball;
                else Btop = ball;
            } else if (Atop < ball) {
                Atop = ball;
            } else if (Btop < ball) {
                Btop = ball;
            } else {
                fine = false;
            }
        }
        cout << (const char *)(fine ? "YES" : "NO") << endl;
    }
}

C++: #include<vector>
#include<iostream>
using namespace std;
const int maxn=15;
int sum[maxn];
bool check(int i,vector<int> &left,vector<int> &right)
{
	int a=left.size()-1,b=right.size()-1;
	if(i==10&&left[a-1]<left[a]&&right[b-1]<right[b])
		return true;
	if(a>=1)
	{
		if(left[a-1]<left[a])
		{
	left.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
		}
		else
			return false;
	}
	else
	{
		left.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
	}
	left.pop_back();
	if(b>=1)
	{
		if(right[b-1]<right[b])
		{
			right.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
		}
		else
			return false;
	}
	else
	{
	right.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
	}
	right.pop_back();
	return false;
}
int main()
{
	int N;
	cin>>N;
	while(N--)
	{
		vector<int> left,right;
		for(int i=0;i<10;i++)
			cin>>sum[i];
		if(check(0,left,right))
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}