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<bits/stdc++.h>
using namespace std;
int main(){
  int aaaa;cin>>aaaa;
  for(int fdsaf=0;fdsaf<aaaa;fdsaf++){
    int a[10];
    for(int i=0;i<10;i++)
      cin>>a[i];
    int b[10]={};
    int c[10]={};
    b[0]=1;c[0]=0;
    int flag=1;
    int cnt=0;
    for(int i=0;i<2;i++){
      if(i==0){
	b[1]=1;c[1]=0;
      }else{
	b[1]=0;c[1]=1;
      }

      for(int j=0;j<2;j++){
	if(j==0){
	  b[2]=1;c[2]=0;
	}else{
	  b[2]=0;c[2]=1;
	}
	for(int k=0;k<2;k++){
	  if(k==0){
	    b[3]=1;c[3]=0;
	  }else{
	    b[3]=0;c[3]=1;
	  }
	  for(int l=0;l<2;l++){
	    if(l==0){
	      b[4]=1;c[4]=0;
	    }else{
	      b[4]=0;c[4]=1;
	    }
	    for(int m=0;m<2;m++){
	      if(m==0){
		b[5]=1;c[5]=0;
	      }else{
		b[5]=0;c[5]=1;
	      }
	      for(int n=0;n<2;n++){
		if(n==0){
		  b[6]=1;c[6]=0;
		}else{
		  b[6]=0;c[6]=1;
		}
		for(int o=0;o<2;o++){
		  if(o==0){
		    b[7]=1;c[7]=0;
		  }else{
		    b[7]=0;c[7]=1;
		  }
		  for(int p=0;p<2;p++){
		    if(p==0){
		      b[8]=1;c[8]=0;
		    }else{
		      b[8]=0;c[8]=1;
		    }
		    for(int q=0;q<2;q++){
		      if(q==0){
			b[9]=1;c[9]=0;
		      }else{
			b[9]=0;c[9]=1;
		      }
		      int bpointer=0;
		      int cpointer=0;
		      for(int r=0;r<10;r++){
			//cout<<a[r]<<" "<<b[r]<<" "<<c[r]<<endl;
			if(b[r]==1){
			  if(bpointer<a[r]){
			    bpointer=a[r];
			    if(r==9){
			      flag=0;
			      cout<<"YES"<<endl;
			      break;
			    }
			  }else{
			    break;
			  }
			}else if(c[r]==1){
			  //cout<<"!"<<endl;
			  if(cpointer<a[r]){
			    cpointer=a[r];
			    if(r==9){
			      flag=0;
			      cout<<"YES"<<endl;
			      break;
			    }
			  }else{
			    break;
			  }
			}
		      }
		      if(flag==0)break;
		    }
		    if(flag==0)break;
		  }
		  if(flag==0)break;
		}
		if(flag==0)break;
	      }
	      if(flag==0)break;
	    }
	    if(flag==0)break;
	  }
	  if(flag==0)break;
	}
	if(flag==0)break;
      }
      if(flag==0)break;
    }
    if(flag)
      cout<<"NO"<<endl;
  }
  return 0;
}

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

int main(){
    int n,s;
    cin >> n;
    for (int i=0; i < n; i++){
        int a=0, b=0, flg=0;
        for (int j = 0; j < 10; j++){
            cin >> s;
            if (s > a) a=s;
            else if (s > b) b=s;
            else flg = 1;
        }
        printf("%s\n", flg==0? "YES": "NO");
    }
}

C++: //AOJ 0033

#include<iostream>

using namespace std;

int main(){

	int n;

	cin>>n;

	int **data = new int*[n];
	for(int i=0;i<n;i++){
		data[i] = new int[10];
	}

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

	int youki[2]={0,0};
	int state = 0;
	int flag = 0;

	for(int i=0;i<n;i++){
		for(int k=0;k<2;k++){
			youki[k] = 0;
		}
		for(int j=0;j<10;j++){
			state = 0;
			flag = 0;
			for(int k=0;k<2;k++){

				if(youki[k]<=data[i][j]){
					youki[k] = data[i][j];
					state = 1;//ボール入れられた！
					break;
				}
			}
			if(state==0){
				cout<<"NO"<<endl;
				break;
			}
			if(state == 1 && j == 9){
				flag = 1;
			}
		}
		if(flag == 1){
			cout<<"YES"<<endl;

		}
		
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	for (int t = 0; t < n; ++t) {
		int a[10];
		for (int i = 0; i < 10; ++i) cin >> a[i];

		bool ans = false;
		for (int k = 0; k < (1 << 10); ++k) {
			int top[2] = {-1, -1};
			bool f = true;
			for (int i = 0; i < 10; ++i) {
				int tid = k & (1 << i) ? 1 : 0;
				if (a[i] < top[tid]) {
					f = false;
					break;
				}
				top[tid] = a[i];
			}
			ans |= f;
		}

		if (ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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("\nNO");
			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("\nYES");
	}			
}
return 0;
}

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

int func( int *ball, int n, int cur, stack<int> b, stack<int> c){
    int ball_cur = ball[cur];
    int count=0;
    
    if(cur == n){
        return 1;
    }    
    if(b.empty() || b.top() < ball_cur ){
        b.push(ball_cur);
        count+=func(ball, n, cur+1, b, c);
        b.pop();
    }
    if(c.empty() || c.top() < ball_cur ){
        c.push(ball_cur);
        count+=func(ball, n, cur+1, b, c);
        c.pop();
    }
    return count;    
}

int main(){
    int n;
    int ball[10];
    stack<int> stk_b,stk_c;
    
    cin>>n;
    for(int i=0;i<n;++i){
        for(int j=0;j<10;++j){
            cin>>ball[j];
        }
        cout << (func(ball, 10, 0, stk_b, stk_c)?"Yes":"No") << endl;
        
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
#define RIGHT 1
#define LEFT 0
#define BALL 10
#define BAD 1

int main()
{
    int n;
    int num[BALL];
    int siden[BALL];
    cin >> n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<BALL;++j) {cin >> num[j]; }

        int temp,ans =0;
        for(int side=0;side<=0x3F;++side)
        {
            ans = 0;
            for(int j = 0;j<BALL;++j)
            {
                if(((side>>j)&1) ){siden[j] = RIGHT;}
                else {siden[j] = LEFT;}
            }
            int before = -1;
            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==RIGHT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            before = -1;

            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==LEFT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            if(ans==0)break;
        }
        if(ans==BAD) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

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

#define MAX_W 100
#define MAX_H 100

char room[MAX_W][MAX_H];
int W,H;

const int direc[4][2] = {
    {0, -1},
    {1, 0},
    {0, 1},
    {-1, 0},
};

void dfs(const int& row, const int& col, const char c);

int main() {
    while(cin>>H>>W, W > 0) {
        int step = 0;
        int col, row;
        for (row = 0; row < H; ++row) {
            for (col = 0; col < W; ++col) {
                cin >> room[row][col];
            }
        }
        for (row = 0; row < H; ++ row) {
            for(col = 0; col < W; ++ col) {
                if(room[row][col] != '!') {
                    dfs(row, col, room[row][col]);
                    ++ step;
                }
            }
        }
        cout<<step<<endl;
    }
    return 0;
}

void dfs(const int& row, const int& col, const char c) {
    room[row][col] = '!';
    for(int d = 0; d < 4; ++ d) {
        int curRow = row + direc[d][1];
        int curCol = col + direc[d][0];
        if(curRow >= 0 && curRow < H && curCol >= 0 && curCol < W && room[curRow][curCol] == c) {
            dfs(curRow, curCol, c);
        }
    }
}