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 a[10],n,i;
	bool can;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			for(int j = 0;j<10;j++){
				cin >> a[j];
			}
			for(int j = 1;j<=7;j+=2){
				if(a[j] < a[j+2] && a[j-1] < a[j+1]) can = true;
				else {
					can = false;
					break;
				}
			}
			if(can == true) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

// const int kMaxN;

int N;
int D[10];
string ans;

string Search(int i, vector<int> d1, vector<int> d2) {
  if (i == 10) { return "Yes"; }

  if (d1.empty() || d1.back() < D[i]) {
    d1.push_back(D[i]);
    if (Search(i+1, d1, d2) == "Yes") { return "Yes"; }
    d1.pop_back();
  }
  if (d2.empty() || d2.back() < D[i]) {
    d2.push_back(D[i]);
    if (Search(i+1, d1, d2) == "Yes") { return "Yes"; }
  }

  return "No";
}

signed main() {
  cin >> N;

  while (N-- > 0) {
    REP(i, 10) { cin >> D[i]; }
    vector<int> d1, d2;
    ans = Search(0, d1, d2);
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

int num[10];
bool test(int l_num, int r_num, int i) {
  if (i >= 10) return true;
  if (num[i] > l_num && num[i] > r_num) return test(num[i], r_num, i+1) || test(l_num, num[i], i+1);
  if (num[i] > l_num) return test(num[i], r_num, i+1);
  if (num[i] > r_num) return test(l_num, num[i], i+1);
  return false;
}

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

  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int n;
  int b[10]={0};
  int c[10]={0};
  int bcount=0,ccount=0,h=0;
  for(int i=0;i<t;i++){
    for(int j=0;j<10;j++){
      cin >> n;
      if(b[0]==0) b[bcount] = n;
      else if(b[bcount]>c[ccount]&&b[bcount]<n){
    bcount++;
    b[bcount] = n;
      }
      else if(c[ccount]>b[bcount]&&c[ccount]<n){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n;
      }
      else if(b[bcount]>c[ccount]&&b[bcount]>n&&c[ccount]<n){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n;
      }
      else if(c[ccount]>b[bcount]&&c[ccount]>n&&b[bcount]<n){
    bcount++;
    b[bcount] = n;
      }
      else if(b[bcount]>n&&c[ccount]>n){
    cout << "NO" << endl;
    h = 1;
    break;
      }
    }
    if(h==0) cout << "YES" << endl;
    for(int i=0;i<10;i++){
      b[i] = 0;
      c[i] = 0;
    }
      bcount = 0;
      ccount = 0;
      h = 0;
  }
  return 0;
}

C++: #include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>


using namespace std;

typedef pair<int,int> P;


const int N=10000;
int ball[10];
int n=0;

int A[10],B[10];

bool solve(int i,int a,int b,bool IS_A){

  //cout<<"a,b:"<<a<<","<<b<<endl;
  
  if(i==10) return true;

  if(IS_A){
    A[a]=ball[i];
    if(a>0 && A[a-1]>A[a]){
      //cout<<"hoge"<<endl;
      return false;
    }
    a++;
  }
  else{
    B[b]=ball[i];
    if(b>0 && B[b-1]>B[b]){
      //cout<<"huge"<<endl;
      return false;
    }
    b++;
  }
  
  bool t1,t2;
  
  //when ball[i] is pushed into A or B
  return (solve(i+1,a,b,true)||solve(i+1,a,b,false));
}





int main(){

  cin>>n;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>ball[j];
    }
    if(solve(0,0,0,true)||solve(0,0,0,false)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }


  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int b = 11,c = 11;
  cin >> n;
  while(n--){
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b > a)b = a;
      else if(c > a)c = a;
      else {
	cout << "NO" << endl;
	return;
      }  
    }
    cout << "YES" << endl;
  }
}

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

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int a[10];
        bool f = 0;
        for(int j=0; j<10; j++) cin >> a[j];
        for(int j=0; j<8; j++) {
            if(a[j] > a[j+1] && a[j+1] > a[j+2]) {
                f = 1;
                break;
            }
        }
        printf("%s\n", f ? "NO" : "YES");

    }

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>

typedef long long LL;
using namespace std;

const int cnt = 10;
int num[cnt];
vector<int> a, b;

bool DFS(int i)
{
	if (i == 10) return true;
	if (num[i] > a.back()) {
		// cout << i << " sum1 " << num[i] << endl;
		a.push_back(num[i]); if (DFS(i + 1)) return true; a.pop_back();
	}
	if (num[i] > b.back()) {
		// cout << i << " sum2 " << num[i] << endl;
		b.push_back(num[i]); if (DFS(i + 1)) return true; b.pop_back();
	}
	return false;
}


int main()
{
	int T;
	scanf("%d", &T);
	while(T--) {
		for (int i = 0; i < cnt; i++) scanf("%d", &num[i]);
		a.clear(); b.clear(); b.push_back(num[0]); a.push_back(0);
		if (DFS(1)) cout << "YES\n";
		else cout << "NO\n";
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){
	int n,a,b,c;
	bool f;
	cin>>n;
	for(int i=0;i<n;i++){
		f=true;b=0;c=0;
		for(int j=0;j<10;j++){
			cin>>a;
			if(b>a&&c>a){
				f=false;
				break;
			}else if(b<a && c<a){
				if(b>=c)b=a;
				else c=a;
			}else if(b<a){
				b=a;
			}else if(c<a){
				c=a;
			}
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ball[10];
bool can = false;

void search(int r,int l,int n){
  cout << n << endl;
  if(n>=10) can = true;
  if(r<ball[n]) search(ball[n],l,n+1);
  if(l<ball[n]) search(r,ball[n],n+1);

}
 
int main(){
  int n;
  cin >> n;
  REP(i,n){
	REP(i,10) cin >> ball[i];
	int right=0;
	int left=0;
	can = false;
	search(right,left,0);
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
  }

}