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++: /*
100
1 2 4 6 7 8 9 10
3 5
NO
*/
#include<cstdio>
int n,j,lj,F;
int a[15],f[15];
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		j=0;F=0;lj=0;
		for(int i=1;i<=10;i++)
		f[i]=0,a[i]=0; 
		for(int i=1;i<=10;i++)
		scanf("%d",&a[i]);
		lj=1;
		for(int i=1;i<=9;i++)
		if(a[i+1]>a[lj]) f[lj]=1,lj=i+1;
		if(a[10]>f[lj]) f[lj]=1;
		for(int i=1;i<=10;i++)
		printf("%d ",f[i]);
		lj=0;
		a[0]=0;
		for(int i=1;i<=10;i++)
		if(!f[i])
		{
			if(a[i]>a[lj]) lj=i;
			else {printf("NO\n");F=1;break;}
		}
		if(!F) 
		printf("YES\n");
	}
}
/*
#include <iostream>  
  
using namespace std;  
  
const int N = 10;  
  
int main()  
{  
    int n;  
  
    cin >> n;  
    while(n--) {  
        bool ans = true;  
        int a, b=-1, c=-1;  
        for(int i=1; i<=N; i++) {  
            cin >> a;  
            if(ans) {  
                if(a > b)  
                    b = a;  
                else if(a > c)  
                    c = a;  
                else  
                    ans = false;  
            }  
        }  
  
        cout << (ans ? "YES" : "NO") << endl;  
    }  
  
    return 0;  
}  
*/

C++: #include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  while(N--){
    int B=0,C=0,i=0,b[10];
    bool f=true;
    cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9];
    while(i<10){
      cout << b[i] << endl;
      if(B<b[i]){
	if(B<C&&C<b[i])C=b[i];
	else B=b[i];
      }else if(C<b[i]){
	C=b[i];
      }else{
	f=false;break;
      }
      i++;
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

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

int main(){
  bool ans;
  int n;
  int a[10],b,c;
  cin>>n;
  for(int i=0;i<n;i++){
    ans=true;
    for(int j=0;j<10;j++)cin>>a[j];
    b=c=0;

    for(int j=0;j<10;j++){
      if(a[j]<b&&a[j]<c){ans=false;break;
      }else if(b<a[j]&&c<a[j]){
	if(b>c)b=a[j];
	else c=a[j];
      }
      else if(b<a[j]&&c>a[j])b=a[j];
      else if(b>a[j]&&c<a[j])c=a[j];
    if(b>c)b=a[j];
    else c=a[j];
    }	
    
    if(ans==true)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;  
  }
  
}

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

int main(){
  bool ans;
  int n;
  int a[10],b,c;
  cin>>n;
  for(int i=0;i<n;i++){
    ans=true;
    for(int j=0;j<10;j++)cin>>a[j];
    b=c=0;
    for(int j=0;j<10;j++){
      if(a[j]<b&&a[j]<c){ans=false;break;
      }else if(b<a[j]&&c<a[j]){
	if(b>a[j])b=a[j];
	else c=a[j];
      }
      else if(b<a[j]&&c>a[j])b=a[j];
      else if(b>a[j]&&c<a[j])c=a[j];
    if(b>c)b=a[j];
    else c=a[j];
    }	
    
    if(ans==true)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;  
  }
  
}

C++: #include<stdio.h> 
#include<string.h>
int s[12];
bool p[12];
int flag,flag1,A;
void dfs(int com,int cur)
{
	if(cur==10)
	return;
	if(s[com]<=s[cur] && !p[cur])
		p[com]=true,p[cur]=true,dfs(cur,cur+1);
	else if(s[com]>s[cur] || p[cur])
		{
			if(flag1)
			flag1=0,A=cur;
	    	dfs(com,cur+1);	
		}
}
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		flag=1,flag1=1;
		memset(p,false,sizeof(p));
		for(int i=0;i<10;i++)
		scanf("%d",&s[i]);
		dfs(0,1);
		dfs(A,A+1);
		for(int i=0;i<10;i++)
			if(!p[i])
				flag=0;
		if(flag)
		printf("YES");
		else
		printf("NO");
		printf("\n");
	 } 
	return 0;
 }

C++: #include <cstdio>
int main()
{
 int set[1000][10],i,j,cnt;
 int t[1000]={1};
 scanf("%d",&i);

 for(cnt=0;cnt<i;cnt++)
{
	for(j=0;j<10;j++)scanf("%d",&set[cnt][j]);
	for(j=0;j<8;j++)
	{
	if(set[cnt][j+2]<set[cnt][j+1]&&set[cnt][j+2]<set[cnt][j])t[cnt]=0;
	}
	
	if(t[cnt]==0)puts("NO");
	if(t[cnt]==1)puts("YES");
}

return 0;
}

C++: 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////




int main(){
    int n;cin>>n;
    while(n--){
        int a[10];for(int i=0;i<=9;i++)cin>>a[i];
        int b=0,c=a[0];int i=1;
        while(i<=9){
            if(c<a[i])c=a[i];
            else if(b<a[i])b=a[i];
            else break;
            i++;
        }
        i==10?cout<<"YES"<<endl:cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int n;
int ba[10];

bool all(int,int,int);

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ba[j];
    }
    if(all(0,0,0)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

}

bool all(int end,int l,int r){
  if(end==10){
    return true;
  }else if(ba[end]>l){
    return all(end+1,ba[end],r);
  }else if(ba[end]>r){
    return all(end+1,l,ba[end]);
  }
  return false;
}

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

int n;
int a[1000];
int a1[1000];
int a2[1000];
void dfs(int s,int s1, int s2){
    if(s==10){
        return ;
    }
    if(s1==0 && s2==0){
        a1[s1]=a[s];
        dfs(s+1,s1+1,s2);
    }else{
        if(s1==0){
            if(a2[s2-1]<a[s]){
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }else{
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }
        }else if(s2==0){
            if(a1[s1-1]<a[s]){
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }else{
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }
        }else{
            if(a1[s1-1]<a[s]){
                a1[s1] = a[s];
                dfs(s+1,s1+1,s2);
            }else if(a2[s2-1]<a[s]){
                a2[s2] = a[s];
                dfs(s+1,s1,s2+1);
            }else{
                return ;
            }
        }
    }
}
int main(){
    while(~scanf("%d",&n)){
        while(n--){
            for(int i=0;i<10;i++){
                scanf("%d",&a[i]);
            }
            memset(a1,-1,sizeof(a1));
            memset(a2,-1,sizeof(a2));
            dfs(0,0,0);
            int i=0,j=0;
            for(;;i++){
                if(a1[i]==-1){
                    break;
                }
            }
            for(;;j++){
                if(a2[j]==-1){
                    break;
                }
            }
            if(i+j==10){
                printf("YES\n");
            }else{
                printf("NO\n");
            }
        }
    }
}

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

using namespace std;

int main() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			int k = A[j];
			if (B.empty() != true && C.empty() != true) {
				if (B.top() > k && C.top() > k) {
//					cout << k << " " << B.top() << " " << C.top() << endl;
					ans = "NO";
					break;
				}
				else if (B.top() > C.top())
					B.push(k);
				else
					C.push(k);
			}
			else if (B.empty() == true)
				B.push(k);
			else if (B.top() < k)
				B.push(k);
			else if (B.top() > k)
				C.push(k);
		}
		cout << ans << endl;
	}
	return 0;
}