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<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>


using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)

stack<short> left, right;
short a[10], n, j;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(left.top() < a[c]){
		left.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(right.top() < a[c]){
		right.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) left.pop();
	else right.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	FOR(n){
		left.push(0);
		right.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

C++: #include <stdio.h>

int
main(void)
{
	char line[80];

	int b[10];

	int n;
	
	if (fgets(line, sizeof line, stdin) == NULL) {
		return 0;
	}
	if (sscanf(line, "%d", &n) != 1) {
		return 0;
	}
	
	while (n--) {
		if (fgets(line, sizeof line, stdin) == NULL) {
			break;
		}
		if (sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
				   &(b[0]), &(b[1]), &(b[2]), &(b[3]), &(b[4]), &(b[5]),
				   &(b[6]), &(b[7]), &(b[7]), &(b[9])) != 10) {
			break;
		}

		bool f = true;
		int s0 = 0;
		int s1 = 0;
		for (int t : b) {
			if (t > s0 && t > s1) {
				if (t - s0 <= t - s1) {
					s0 = t;
				} else {
					s1 = t;
				}
			} else 	if (t > s0) {
				s0 = t;
			} else 	if (t > s1) {
				s1 = t;
			} else {
				f = false;
				break;
			}
		}
		printf("%s\n", (f ? "YES" : "NO"));
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int main() {
	int n; cin >> n;
	while (n--) {
		int l = 0, r = 0;
		bool ok = true;
		rep(i, 10) {
			int b; cin >> b;
			if(l < b) l = b;
			else if (r < b) r = b;
			else ok = false;
		}
		cout << (ok ? "YES" : "NO" ) << endl;
	}
	return 0;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    cin >> n;
    rep(i, n) {
        int l = 0, r = 0;
        bool f = true;
        rep(i, 10) {
            int t;
            cin >> t;
            if (t > l) l = t;
            else if (t > r) r = t;
            else f = false;
        }
        P(f ? "YES" : "NO");
    }
    return 0;
}

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

int BALLNUM = 10;

	static int data[10];
class balldata
{
private:
	//static std::vector <int> data;
	//int ballnum;
public:
	balldata(int datanum);
	static void enter();
	static void answer();
	static bool check();
	static bool check(int num,int right,int left);
};




int main()
{
	balldata ball(BALLNUM);

int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		ball.enter();
		ball.answer();
	}
}


balldata::balldata(int datanum)
{
	//ballnum = datanum;
	//data.resize(datanum);
}



void balldata::enter()
{
	for (int i = 0; i < 10; i++)
	{
		std::cin >> data[i];
	}
	return;
}

bool balldata::check(int num,int right,int left)
{
	//if (num == data.size())return true;
	if (num == 10)return true;
	if (balldata::check(num + 1, right, data[num])&&left<data[num]){ return true; }
	if (balldata::check(num + 1, data[num], left)&&right<data[num]){ return true; }

	return false;
}
bool check()
{
	return balldata::check(0, 0, 0);
}

void balldata::answer()
{ 
	if (balldata::check(0, 0, 0))
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;
	}
}