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++: /*
テヲテδ欲ツ法ツづ可づヲツづィツ嘉ーツつッツづ慊つキ(ツつ?づィツ本ツ妥ヲ2ツ氾?づ?P.24ツつセツづヲツ！)
- ツ債カツづ個暗ェツ氾板湘」ツづ個仰?づ個値ツづ? ツ右ツづ個暗ェツ氾板湘」ツづ個仰?づ個値ツづーツ個ゥツ氾、ツづ猟づ?
  ツ妥・ツつォツつ「ツ値ツづ個個環づ個陛サツづ? ツ仰?づーツ禿シツづェツづァツづェツづゥツづ按づァツ禿シツづェツつスツ陛サツつェツつ「ツつ「.
- ツつアツづェツづ? ツ渉ャツつウツつ「ツ値ツづ個個環づーツ残ツつオツつスツ陛サツつェ, ツ古」ツ々ツつィツ督セツづ可づ按づゥツつゥツづァツづ?つキ.
- ツ「ツ妥・ツつォツつ「ツ陛サツづ可禿シツづェツづァツづェツづゥツづ按づァツ禿シツづェツづゥツ」ツ?ィツ「ツつサツづェツづ?つセツづ淞づ按づァツ渉ャツつウツつ「ツ陛サツづ可禿シツづェツづゥツ」ツ?ィツ「ツつサツづェツづ?づ?ダツδ?づ按づァNOツ」ツづーツδ仰ーツプツづ?繰ツづィツ陛板つオツづ慊つオツづ・ツつ、.
 */
#include <iostream>
using namespace std;

int main(){
  int T;
  cin >> T;

  while(T--){
    int b = 0; //ツ?ゥツづ個つ?づ?
    int c = 0; //ツ?ィツづ個つ?づ?
    bool ans = true; //ans == trueツづ按づァYES, ans == falseツづ按づァNO

    for(int i = 0; i < 10; i++){
      int a;
      cin >> a;

      //ツつキツづ?づ丑Oツづ?づュツつゥツづ?づ?つ「ツづゥツづ按づァ, ツ渉按猟敖づーツつケツつクcontinue
      if(!ans) continue;

      //ツ?ゥツづ個個環づ個暗ェツ氾板湘」ツづ個値ツづヲツづィ, ツ?ィツづ個個環づ個暗ェツ氾板湘」ツづ個値ツづ個陛サツつェツ妥・ツつォツつ「
      if(b < c){
        if(c < a)      c = a;       //ツ妥・ツつォツつ「ツ陛サ(ツ?ィ)ツづ可湘ヲツつケツづァツづェツづゥツづ按づァツ湘ヲツつケツづゥ(ツつサツづ個陛サツつェツ古」ツ々ツ督セツつセツつゥツづァ)
        else if(b < a) b = a;
        else           ans = false; //ツ渉ャツつウツつ「ツ陛サ(ツ?ゥ)ツづ可づ?湘ヲツつケツづァツづェツづ按つゥツづ?つスツづァ, NOツづ?づ按づゥ
      }
      //ツ?ゥツづ個個環づ個暗ェツ氾板湘」ツづ個値ツづヲツづィ, ツ?ィツづ個個環づ個暗ェツ氾板湘」ツづ個値ツづ個陛サツつェツ渉ャツつウツつ「
      else{
        if(b < a)      b = a;       //ツ妥・ツつォツつ「ツ陛サ(ツ?ゥ)ツづ可湘ヲツつケツづァツづェツづゥツづ按づァツ湘ヲツつケツづゥ(ツつサツづ個陛サツつェツ古」ツ々ツ督セツつセツつゥツづァ)
        else if(c < a) c = a;
        else           ans = false; //ツ渉ャツつウツつ「ツ陛サ(ツ?ィ)ツづ可づ?湘ヲツつケツづァツづェツづ按つゥツづ?つスツづァ, NOツづ?づ按づゥ
      }
    }

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

C++: #include <iostream>

using namespace std;

int a[10];
bool flag;

void dfs(int n, int l, int r) 
{
    if (n == 10) {
        flag = true;
        return ;
    }

    if (a[n] > l)
        dfs(n + 1, a[n], r);
    if (a[n] > r)
        dfs(n + 1, l, a[n]);

    return ;
}

int main()
{
    int n;

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

        flag = false;
        dfs(0, 0, 0);
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

C++: #include<stdio.h>
#include<string.h>
int a[13],vis[13],flag;
void dfs(int x,int l,int r)
{
    int i;
    if(x==11)return; 
    if(flag)return ;
    if(a[x]>l)dfs(x+1,a[x],r);
    else  if(a[x]>r)dfs(x+1,l,a[x]);
    else  {flag=1;return;}
}
int main()
{
int T,i,j,k;
scanf("%d",&T);
while(T--)
{
flag=0;
for(i=1;i<=10;i++)
scanf("%d",&a[i]);
memset(vis,0,sizeof(vis));
dfs(1,0,0);
if(flag)printf("NO\n");
else printf("YES\n");
}
return 0;
}

C++: #include<iostream>

int ball[10];
bool res;

void dfs(int i, int ls, int rs){
	if (i == 10){
		res = true;
		return;
	}

	if (ball[i] > ls)dfs(i + 1, ball[i], rs);
	if (ball[i] > rs)dfs(i + 1, ls, ball[i]);
}

int main(){
	int n;
	std::cin >> n;

	for (int i = 0; i < n; i++){
		for (auto &i : ball)std::cin >> i;
		res = false;
		dfs(0, 0, 0);
		std::cout << (res ? "YES" : "NO") << std::endl;
	}
	return 0;
}

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

int a[10];
bool flag;

void dfs(int x, int l, int r){
	if(x == 10){
		flag = true;
		return;
	}
	if(a[x] > l)
		dfs(x+1, a[x], r);
	else if(a[x] > r)
		dfs(x+1, l, a[x]);
	else flag = false;
}
int main(){
	int N;
	scanf("%d", &N);
	while(N--){
		memset(a, 0, sizeof(a));
		for(int i = 0; i < 10; i++) scanf("%d", &a[i]);
		flag = false;
		dfs(0, 0, 0);
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: //
//  AOJ 0033 Ball
//
//  Created by TaoSama on 2015-02-19
//  Copyright (c) 2014 TaoSama. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define CLR(x,y) memset(x, y, sizeof(x))

using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

int a[15];
bool dfs(int k, int b, int c) {
	if(k == 11) return true;
	if(a[k] > b) if(dfs(k + 1, a[k], c)) return true;
	if(a[k] > c) if(dfs(k + 1, b, a[k])) return true;
	return false;
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	int t; cin >> t;
	while(t--) {
		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>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;



int main(){
	int n;

	cin >> n;
	while(n--){
		int a;
		bool f = true;
		vector<int> b, c; 
		for(int i = 0; i < 10; i++){
			cin >> a;
			if(f || b[b.size()-1] < a){
				b.push_back(a);
				f = false;
			}else{
				c.push_back(a);
			}
		}
		bool check = true;
		for(int i = 1; i < b.size() && check; i++){
			if(b[i] < b[i-1]){
				check = false;
			}
		}
		for(int i = 1; i < c.size() && check; i++){
			if(c[i] < c[i-1]){
				check = false;
			}
		}
		
		if(check){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int n; cin >> n;
    int x;
    rep(k,0,n) {
        int a = 0, b = 0;
        bool can = true;
        rep(i,0,10) {
            cin >> x;
            if(a < x && b < x){
                if(x - a > x - b) b = x;
                else a = x;
            }
            else if(a < x) a = x;
            else if(b < x) b = x;
            else {can = false;}
        }
        if(can) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}