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;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
int a[11];

void bitBruteForth() {
   bool printed = false;
   rep (mask, (1<<10)) {
      bool ok = true;
      int oldA = -1, oldB = -1;
      rep (j, 10) {
         if ((mask>>j)&1) {
            if (a[j] > oldA) {
               oldA = a[j];
            } else {
               ok = false;
            }
         } else {
            if (a[j] > oldB) {
               oldB = a[j];
            } else {
               ok = false;
            }
         }
      }
      if (ok) {
         puts("YES");
         printed = true;
         break;
      }
   }
   if (!printed) puts("NO");
}

bool rec(int idx, int l, int r) {
   if (idx == 10) return true;

   bool x = false, y = false;
   int val = a[idx];
   if (l < val) x = rec(idx+1, val, r);
   if (r < val) y = rec(idx+1, l, val);

   return x || y;
}

int main() {
   cin >> n;
   while (n--) {
      rep (i, 10) cin >> a[i];
      puts(rec(0, -1, -1)?"YES":"NO");
   }

   return 0;
}

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

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

int main(){
	int b, c, n, a, i, j;
	bool executable;
	cin >> n;
	for(i=0;i<n;i++){
		executable = true;
		cin>>a;
		b=a;
		c=0;
		for(j=1;j<10;j++){
			cin>>a;
			if(a-b < 0){
				if(a-c < 0){
					executable = false;
				}else{
					c = a;
				}
			}else{
				if(a-c < 0){
					b = a;
				}else{
					if(c < b){
						b = a;
					}else{
						c = a;
					}
				}
			}
		}
		if(executable){
			cout << "YES\n";
		}else{
			cout << "NO\n";
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main(){
  int n=0;
  int a[10];
  int ans=0;
  cin>>n;
  //  while(scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9])){
  for(int j=0;j<n;j++){
    for(int k=0;k<10;k++){
      cin>>a[k];
    }
    ans=0;
    int l=0,r=0;
    for(int i=0;i<10;i++){
      if(i==0){
	l=a[i];
      }
      else{
	int ma=max(l,r);
	int mi=min(l,r);
	if(a[i]>ma){
	  if(l==ma){
	    l=a[i];
	  }
	  else{
	    r=a[i];
	  }
	}
	else if(mi<a[i]&&a[i]<ma){
	  if(l==mi){
	    l=a[i];
	  }
	  else{
	    r=a[i];
	  }
	}
	else{
	  break;
	}
      }
      if(i==9){
	ans=1;
      }
    }

    if(ans==1){
      cout<<"YES\n";
    }
    else{
      cout<<"NO\n";
    }
  }
  return 0;
}

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

using namespace std;
vector<int> ball;
bool search(int l, int r, int n)
{
  if (n == 10) {
    return true;
  }

  if (l < ball[n]) {
    if (search(ball[n], r, n + 1)) {return true;}
  } 
  if (r < ball[n]) {
    if (search(l, ball[n], n + 1)) {return true;}
  }
  return false;
}

int main()
{
  int N;
  scanf("%d ", &N);
  
  for (int i = 0; i < N; i++) {
    ball.clear();
    ball.resize(10);
    for (int i = 0; i < 10; i++) {
      scanf("%d ", &ball[i]);
    }
    if (search(ball[0], 0, 1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define foreach(itr,a) for(__typeof((a).begin()) itr=(a).begin(); itr!=(a).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

int a[11];

void dfs(int depth, int l, int r) {
    if(depth == 10) {
        cout << "YES" << endl;
        return ;
    }

    int t = a[depth];
    if(l < t)
        dfs(depth+1, t, r);
    else if(r < t)
        dfs(depth+1, l, t);
    else
        cout << "NO" << endl;

    return ;
}

int main() {
    int n; cin >> n;
    rep(poyo,n) {
        rep(i,10) cin >> a[i];
        dfs(0,0,0);
    } 

    return 0;
}

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

int main(){
	int n,ball,tp[2],con,bad;
	
	cin >> n;
	
	for(; n > 0; n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				cout << "NO" << endl;
				cin.ignore(64, '\n');
			}
			
			if(i == 9){
				cout << "YES" << endl;
			}
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<bool>l;
	int o[10], n;
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++)
			cin >> o[i];
		int sum = o[i], num = 0;
		for (int k = 0; k < 10;k++) {
			if (o[k] < sum){
				num++;
				sum = o[k];
			}
		}
		l.push_back(!(num >= 2));
	}
	for (bool b : l) {
		if (!b)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	char c;
	cin >> c;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int n[10];
  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[j];
    for(int j=0;j<10;j++){
      if(b[0]==0) b[bcount] = n[j];
      else if(b[bcount]>c[ccount]&&b[bcount]<n[j]){
    bcount++;
    b[bcount] = n[j];
      }
      else if(c[ccount]>b[bcount]&&c[ccount]<n[j]){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n[j];
      }
      else if(b[bcount]>c[ccount]&&b[bcount]>n[j]&&c[ccount]<n[j]){
    if(c[ccount]!=0) ccount++;
    c[ccount] = n[j];
      }
      else if(c[ccount]>b[bcount]&&c[ccount]>n[j]&&b[bcount]<n[j]){
    bcount++;
    b[bcount] = n[j];
      }
      else if(b[bcount]>n[j]&&c[ccount]>n[j]){
    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;
}