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>
using namespace std;
int main(){
int n,i,j,j1,j2,a,k;
cin>>n;
for(i=0;i<n;i++){
j1=j2=0;a=1;
for(k=0;k<10;k++){
cin>>j;
if(j1<j&&j2<j){if(j1<j2)j2=j;else j1=j;}
else if(j1<j)j1=j;
else if(j2<j)j2=j;
else a=0;
}
if(a==1)cout<<"YES"<<endl;else cout<<"NO"<<endl;
}
return 0;
}

C++: // AojTemplete.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdafx.h"
#include<iostream>
#include<vector>
using namespace  std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		bool flag = false;
		int prev;
		int in[10];
		int used[10];
		for (int j = 0; j < 10; j++)
		{
			cin >> in[j];
		}
		prev = in[0];
		vector<int> B;
		vector<int> C;
		for (int j = 0; j < 10; j++)
		{
			if (prev > in[j])
			{
				C.push_back(in[j]);
				used[j] = false;
				continue;
			}
			else
			{
				prev = in[j];
				B.push_back(in[j]);
				used[j] = true;
			}
		}
		prev = C[0];
		for (int j = 0; j < C.size(); j++)
		{
			if (prev > C[j])
			{
				flag = true;
				break;
			}
			else
			{
				prev = C[j];
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include <stack> 
using namespace std;
int ar[10];
stack<int> a,b;
bool dfs(int i)
{
	bool aflag = false,bflag = false;
	if(i!=9)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = dfs(i+1);
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = dfs(i+1);
		}
		return aflag|bflag;
	}
	if(i==9)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = true;
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = true;
		}
		return aflag|bflag;
	}
}
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		for(int i = 0;i<10;i++)
			cin >> ar[i]; 
		cout<<(dfs(0)?"YES":"NO")<<endl;
	}
 }

C++: #include<cstdio>

int main(){
	int n, b, c, t;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		b = c = 0;
		for(int j = 0; j < 10; j++){
			scanf("%d", &t);
			if(b < t){
				b = t;
			}else{
				if(c < t){
					c = t;
					if(b < c){
						t = b;
						b = c;
						c = t;
					}
				}else{
					t = 0;
					j += 10;
				}
			}
		}

		if(t){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <vector>



int t;
std::vector<int> balls(10);


int dfs(int d,int a,int b)
{
  if(d==10)
    {
      return 1;
    }

  //

  if(balls[d] > a   )
    {
      if(dfs(d+1,balls[d],b) == 1 )
        return 1;
    }

  if(balls[d] > b)
    {
      if( dfs(d+1,a,balls[d]) == 1)
        return 1;
    }

  return 0;
}

int main(int argc,char* argv[])
{
  //freopen("in.txt","r",stdin);
  std::cin>>t;
  while(t--)
    {
      for(int i = 0 ; i < 10 ; i++)
        std::cin >> balls[i];
      if(dfs(0,0,0) == 1 )
        std::cout<<"YES"<<std::endl;
      else
        std::cout<<"NO"<<std::endl;
    }
  return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int t=0; t<n; t++){
        int b=0, c=0;
        int a[10];
        int i;
        if(!(cin>>a[0])) break;
        for(i=1; i<10; i++) cin>>a[i];
        for(i=0; i<10; i++){
            if(b<c){
                if(c<a[i]) c=a[i];
                else if(b<a[i]) b=a[i];
                else break;
            }else{
                if(b<a[i]) b=a[i];
                else if(c<a[i]) c=a[i];
                else break;
            }
        }
        cout<<(i==10?"YES\n":"NO\n");
    }
    return 0;
}

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

int main(void){
	queue<int> que;
	int b,c,n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			cin >> b;
			que.push(b);
		}
		b = c = 0;
		bool flag = false;
		while(!que.empty()){
			if(que.front() > b){
				b = que.front();
				que.pop();
			}else if(que.front() > c){
				c = que.front();
				que.pop();
			}else{
				flag = true;
				break;
			}
		}
		if(flag){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	}
}

C++: #include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    
    for(int i=0;i<n;++i){
        
        bool flg=false;
        int maxB=0,maxC=0;
        
        for(int j=0;j<10;++j){
            int tmp;
            cin >> tmp;
            if(maxB<tmp)
                maxB=tmp;
            else if(maxC<tmp)
                maxC=tmp;
            else{
                flg=true;
            }
        }
        
        if(flg)
            cout << "NO" <<endl;
        else
            cout << "YES" <<endl;
        
    }
    
    
    return 0;
}

C++: #include<iostream>
#include<fstream>
#include<stack>
#include<vector>
#include<cstring>
using namespace std;
int a[11];
int b[11];
int c[11];
int flag;
void dfs(int x,int y,int z)
{
	if(x==9)
		flag=1;
	if(a[x]<b[y]&&a[x]<c[z])
		return;
	if(a[x]>b[y])
	{
		b[y+1]=a[x];
		dfs(x+1,y+1,z);
	}
	if(a[x]>c[z])
	{
		c[z+1]=a[x];
		dfs(x+1,y,z+1);
	}
}
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	while(n--)
	{
	flag=0;
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	for(int i=0;i<10;i++)
		cin >> a[i];
	dfs(0,0,0);
	if(flag)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	}	
	return 0;
}

C++: #include <stdio.h>
int RideBack[10];
bool check(int val) {int B=-1,C=-1,q;for (q=9;q>=0;q--,val>>=1) if (val&1) {if (B<RideBack[q]) B=RideBack[q]; else break;} else {if (C<RideBack[q]) C=RideBack[q]; else break;} return (q<0);}
int main() {int N,i;scanf("%d",&N);while (N--) {for (i=9;i>=0;scanf("%d",&RideBack[i--]));for (i=0;i<1024;i++) if (check(i)) break;if (i==1024) puts("NO"); else puts("YES");}return 0;}

C++: #include <iostream>
#include <queue>


int n;
int A[10];

std::queue<int> input;

void solve() {
    bool                            flag = true;
    std::queue< std::pair<int, int> > que; // empty : -1

    que.push( std::make_pair(input.front(), -1) );
    // que.push( std::make_pair(-1, input.front()) );
    input.pop();
    while (!input.empty() && flag) {
        bool b = false;
        // bfs
        std::pair<int, int> p = que.front();
        que.pop();
        int n = input.front();

        if (p.first < n) {
            que.push( std::make_pair(n, p.second) );
            b = true;
            // std::cout << n << '\t' << p.second << std::endl;
        }

        if (p.second < n) {
            que.push( std::make_pair(p.first,  n) );
            b = true;
            // std::cout << p.first << '\n' << n << std::endl;
        }

        if (b) input.pop();

        if (que.empty()) flag = false;
    }

    if (flag) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}


int main() {
    std::cin >> n;
    for (int i=0; i<n; i++) {
        int a;
        for (int j=0; j<10; j++) {
            std::cin >> a;
            input.push(a);
        }
        solve();
    }
    return 0;
}