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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
int a[11];
int a1[11];
int pn=0;
int Flag;
void dfs(int i)
{
    if(Flag==1)
        return;

    if(a[i]>a[a1[pn]])
    {
        a1[++pn]=i;
        for(int m=i+1;m<=10;m++)
        {
            dfs(m);
        }
    }
    else
        return;
    int flag=0;
    for(int m=i+1;m<=10;m++)
    {
        if(a[m]>a[i])
            flag=1;
    }
    int flag2;
    if(flag==0||i==10)
    {
        int a2[11];
        int pm=0;
        for(int n=1;n<=10;n++)
        {
            flag2=0;
            for(int m=1;m<=pn;m++)
            {
                if(n==a1[m])
                   flag2=1;
            }
            if(!flag2)
            {
               a2[++pm]=n;
            }
        }
        int flag3=0;
        for(int m=1;m<pm;m++)
        {
            if(a[a2[m]]>a[a2[m+1]])
                flag3=1;
        }
        if(flag3==0)
        {
            Flag=1;
            return;
        }
        else
        {
            pn--;
            return;
        }
    }

}
int main()
{
    int n;
    
    scanf("%d",&n);
    getchar();
    a[0]=-1;
    a1[0]=0;
    for(int i=1;i<=n;i++)
    {
        Flag=0;
        pn=0;
        for(int j=1;j<=10;j++)
        {
            scanf("%d ",&a[j]);
        }
        dfs(1);
        if(Flag==0)
        {
            printf("NO\n");
        }
        else
            printf("YES\n");
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int a[20],b[20],c[20];
    int n;
    cin >> n;
    while (n--)
    {
        bool judge = true;
        for (int i = 1; i <= 10; ++i)
            cin >> a[i];
        int cb = 1,cc = 1;
        b[cb++] = a[1],c[cc++] = a[2];
        for (int i = 3; i <= 10; ++i)
        {
            int cha1 = a[i] - b[cb-1];
            int cha2 = a[i] - c[cc-1];
            if (cha1 < 0 && cha2 < 0)
            {
                judge = false;
                break;
            }
            if (cha1 < 0)
                c[cc++] = a[i];
            if (cha2 < 0)
                b[cb++] = a[i];
            if (cha1 < cha2)
                b[cb++] = a[i];
            else c[cc++] = a[i];
        }
        if (judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: /******************************************
    > File Name: Aoj_0033.cpp
    > Author: universal42
    > Mail: universal42@163.com 
    > Created Time: 2019年05月03日 星期五 16时38分31秒
 ******************************************/

#include<bits/stdc++.h>
#define ll long long int
#define inf 0x3f3f3f3f
#define LOCALa
using namespace std;
const int maxn=1e5+5;
int n;
int arr[10],a[10],b[10];
int flag=0;
void dfs(int i,int j){
	if(flag){
		return;
	}
	if(i+j==10){
		for(int p=0;p<i-1;p++){
			if(a[p]>a[p+1]){
				return;
			}
		}
		for(int p=0;p<j-1;p++){
			if(b[p]>b[p+1]){
				return;
			}
		}
		flag=1;
		return;
	}
	a[i]=arr[i+j];
	dfs(i+1,j);
	b[j]=arr[i+j];
	dfs(i,j+1);
}
void solve(){
	scanf("%d",&n);
	while(n--){
		flag=0;
		for(int i=0;i<10;i++){
			scanf("%d",&arr[i]);
		}
		dfs(0,0);
		if(flag){
			puts("YES");
		}
		else{
			puts("NO");
		}
	}
}
int main(){
#ifdef LOCAL
    freopen("in.in","r",stdin);
#endif
    solve();
    return 0;
}

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

int main() {
	int n, x;
	cin >> n;

	for (int i = 0; i++ < n;) {
		int hole[2] = { 0 };
		for (int j = 0; j < 10; j++) {
			cin >> x;

			if (hole[0] < x) {
				hole[0] = x;
			}else if (hole[1] < x) {
				hole[1] = x;
			} else {
				cout << "NO";
				break;
			}

			if (j == 9) {
				cout << "YES";
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int arr[10],used[10];
void DFS(int pre,int cur)
{
   if(cur<10&&arr[pre]<arr[cur])
   {
	   used[cur]=1;
	   DFS(cur,cur+1);
   }
   else if(cur<10&&arr[pre]>=arr[cur])
	   DFS(pre,cur+1);
}
int main()
{
   int T,pre;
   bool judge;
   cin>>T;
   while(T--)
   {
     for(int i=0;i<10;i++)
		 cin>>arr[i];
	 for(int i=0;i<10;i++)
	 {
		 memset(used,0,sizeof(used));
		 used[i]=1;
	     DFS(i,i+1);
		 judge=false;
		 pre=0;
	     for(int j=0;j<10;j++)
		    if(used[j]==0)
				if(pre>=arr[j])
			{
				judge=true;
				break;
			}else pre=arr[j];
		 if(!judge)
		 {
			 cout<<"YES"<<endl;
			 break;
		 }
	 }
	 if(judge)cout<<"NO"<<endl;
   }

}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int a[10];

bool dfs(int n, int l, int r) {
  if (n >= 10) return true;
  if (l < a[n]) if (dfs(n+1, a[n], r)) return true;
  if (r < a[n]) if (dfs(n+1, l, a[n])) return true;
  return false;
};

int main() {
  int N;
  cin >> N;
  rep(i, 0, N) {
    rep(j, 0, 10) {
      cin >> a[j];
    }
    if (dfs(0, -1, -1)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

  return 0;
};

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		int a=0, b=0, c[15]={0};
		int flag = 0;
		int tmp = 0;
		for(int k =0;k<10;k++){
			cin >> c[k];
		}
		for(int k =0;k<10;k++){
			if(c[k]>a){
				if(c[k]>b){
					b=c[k];
				}
				else{
					a=c[k];
				}
			}
			else{
				flag = 1;
				break;
			}	
		}
		if(flag)cout << "NO"<<endl;
		else cout << "YES"<<endl;
		
	}
	
}

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

int main(){
  int N,t,B,C;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    B = C = 0;
    int j;
    for( j = 0; j < 10; j++){
      cin >> t;
      if(B >= t && C >= t) break;
      else if(B < t && C < t){
	if(B < C) C = t;
	else B = t;
      }
      else if(B < t) B = t;
      else if(C < t) C = t;
      //      cout << B << " ";
    }
    if(j == 10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main(void){
	int num;
	queue<int> qu;
	int a,b;
	int n;

	cin>>n;
	while(n--){
		for(int i=0;i<10;i++){//ツボツーツδ仰づーツ詰ツづ淞づゥ
			cin>>num;
			qu.push(num);
		}
		a=0;
		b=0;
		while(1){
			if(a < qu.front()){
				a=qu.front();
			}else if(b < qu.front()){
				b=qu.front();
			}else{
				cout<<"NO"<<endl;
				break;
			}
			qu.pop();
			if(qu.empty()==true){
				cout<<"YES"<<endl;
				break;
			}
		}
	}
	return 0;
}