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<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<stack>
using namespace std;

int dataSet[10];
bool bz_flag[10];
stack<int> temp_A,temp_B;

bool test_cl (int data_pos)
{
	if (data_pos<10)
	{
		if (temp_A.empty())
		{
			temp_A.push(dataSet[data_pos]);
			bz_flag[data_pos] = true;
			return test_cl(data_pos + 1);
		}
		else
		{
			if (temp_A.top()<dataSet[data_pos])
			{
				temp_A.push(dataSet[data_pos]);
				bz_flag[data_pos] = true;
				return test_cl(data_pos + 1);
			}
			else
			{
				if (temp_B.empty())
				{
					temp_B.push(dataSet[data_pos]);
					bz_flag[data_pos] = true;
					return test_cl(data_pos + 1);
				}
				else
				{
					if (temp_B.top() < dataSet[data_pos])
					{
						temp_B.push(dataSet[data_pos]);
						bz_flag[data_pos] = true;
						return test_cl(data_pos + 1);
					}
					else
					{
						return false;
					}
				}
			}
		}
	}
	else
	{
		return true;
	}
}

int main ()
{
	int N;
	cin>>N;
	while (N--)
	{
		memset(bz_flag,false,sizeof(bz_flag[0]));
		for (int i=0;i<10;i++)
		{
			cin>>dataSet[i];
		}
		if (test_cl(0) == true)
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
		while (!temp_A.empty())
		{
			temp_A.pop();
		}
		while (!temp_B.empty())
		{
			temp_B.pop();
		}
	}
	return 0;
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] <= 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  len[0] = len[1] = 0;
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

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

int main(){
	int N;
	scanf("%d", &N);
	
	while(N--){
		int a = 0, b = 0, t;
		bool flag = true;
		for(int i = 0; i < 10; i++){
			scanf("%d", &t);
			if(a < t){
				if(b < t){
					(a > b ? a : b) = t;
				}
				else{
					a = t;
				}
			}
			else{
				if(b < t){
					b = t;
				}
				else{
					flag = false;
				}
			}
		}
		printf(flag ? "YES\n" : "NO\n");
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
  int n,val,B,C;
  cin >> n;
  while(n-- >0){
    B = 0;
    C = 0;
    bool fin=false;
    for(int i=0;i<10;i++){
      cin >> val;
      if(val > B && val > C){
	if(B>=C)B=val;
	else C=val;
      }
      else if(val > B)B=val;
      else if(val > C)C=val;
      else fin=true;
    }
    if(fin) cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}

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

int main(){
	int n, j, i, max;
	int a[10];
	int b, c;
	cin >> n;
	for (j = 0; j < n; j++) {
		cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> a[7] >> a[8] >> a[9];
		b = 0;
		c = 0;
		for(i = 0; i < 10; i++){
			if(b > c){
				if (a[i] > b) {
					b = a[i];
				}else if(a[i] > c){
					c = a[i];
				}else{
					break;
				}
			}else{
				if(a[i] > c){
					c = a[i];
				}else if (a[i] > b) {
					b = a[i];
				}else{
					break;
				}
			}
		}

		if(i < 10){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int flag,s[11];
void dfs(int x1,int x2,int y1,int y2,int cnt){
	if(cnt==10){
		flag=1;
		return;
	}
	if(x1>x2||y1>y2){
		return;
	}
	dfs(x2,s[cnt],y1,y2,cnt+1);
	dfs(x1,x2,y2,s[cnt],cnt+1);
}
int main()
{
	int N;
	scanf("%d",&N);
	while(N--){
		flag=0;
		for(int i=0;i<10;i++)
			scanf("%d",&s[i]);
		dfs(0,0,0,0,0);
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: int main(){
 return 0;
}

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

using namespace std;

int nums[10];

bool check_recursion(int i; int left; int right){
	if(i == 10) return true
	if(nums[i] > left) check_recursion(i+1; nums[i], right);
	if(nums[i] > right) check_recursion(i+1; left, nums[i]);
	
	return false;
}

int main(){
	int n;
	bool ans;
	cin>>n;

	for(;n>0;n--){
		 scanf("%d %d %d %d %d %d %d %d %d %d",&nums[0],&nums[1],&nums[2],&nums[3],&nums[4],&nums[5],&nums[6],&nums[7],&nums[8],&nums[9]);
		 ans = check_recursion(0,0,0);

	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int ball;
	int n;
	while(cin >> n){
		bool flag = true;
		int B=0, C=0;
		for(int i=0; i<10; i++){
			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>
using namespace std;
int main(){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		b=0;c=0;f=true;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b<a&&c<a){
				if(b<c)c=a;
				else b=a;
			}
			else if(b<a)b=a;
			else if(c<a)c=a;
			else f=false;
			cout<<b<<" "<<c<<endl;
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		deque<int>b,c;
		bool endflag = false;
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( dummy > b[b.size()-1] )	b.push_back( dummy );
			else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
			else {
				cout << "NO" << endl;
				endflag = true;
				break;
			}
		}
		if( !endflag )	cout << "YES" << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

int N, tm[10];
	cin >> N;
	rep(qq,N){
		bool chk = true;
		int bh=0,ch=0;
		rep(i,10) cin >> tm[i];
		rep(i,10){
			if(bh > tm[i] && ch > tm[i]){
				chk = false;
//				printf("i=%i (%d,%d)\n",i,bh,ch);
				break;
			}
			if(bh > tm[i] && ch < tm[i]) ch =tm[i];
			else if(ch > tm[i] && bh < tm[i]) bh =tm[i];
			else if(tm[i] -bh < tm[i] -ch) bh = tm[i];
			else                    ch = tm[i];
		}
		cout << (chk ? "YES": "NO") << endl;
	}
	return 0;
	
	
}