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<iostream>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int a,b,temp,n;
int main()
{
    int n;
    cin>>n;
    while(n--){
        int flag=1;
        queue<int>que;
        for(int i=0;i<10;i++){
            cin>>temp;
            que.push(temp);
        }
        while(que.size()){
            temp=que.front();
            que.pop();
            if(temp<=a&&temp<=b){
                cout<<"NO\n";
                flag=0;
                break;
            }
            else if(temp<=a&&temp>b)b=temp;
            else if(temp<=b&&temp>a)a=temp;
            else {
                if(a>=b)a=temp;
                else b=temp;
            }
        }
        if(flag)cout<<"YES\n";
    }

    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
	int n;
	cin >> n;
	rep(i, n) {
		stack<int> l, r;
		rep(j, 10) {
			int x;
			cin >> x;
			if (l.size() == 0) {
				l.push(x);
				continue;
			}
			if (r.size() == 0) {
				r.push(x);
				continue;
			}
			if (l.top() < r.top()) {
				if (r.top() < x) {
					r.push(x);
					continue;
				}
				if (l.top() < x) {
					l.push(x);
					continue;
				}
			}
			if (r.top() <= l.top()) {
				if (l.top() < x) {
					l.push(x);
					continue;
				}
				if (r.top() < x) {
					r.push(x);
					continue;
				}
			}
			cout << "NO" << endl;
			goto a;
		}
		cout << "YES" << endl;
a:;
	}
}

C++: #include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
//int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int n;
	cin >> n;
	while (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;
		}
		puts(f ? "YES" : "NO");
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <sstream> 
#define  ll long long
using namespace  std;
const    ll   len=105;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		vector<int>v1;
		vector<int>v2;
		int j=0;
		int w=0,temp;
		for(int i=0;i<10;i++)
		{
			cin>>temp;
			if(i==0)
				v1.push_back(temp);
			else
			{
				if(v1[v1.size()-1]<temp)
					v1.push_back(temp);
				else
				{
					if(v2.size()==0)
						v2.push_back(temp);
					if(v2[v2.size()-1]>temp&&v2.size()!=0)
						w=1;
					else
					if(v2[v2.size()-1]<temp&&v2.size()!=0)
						v2.push_back(temp); 	
				}  
			}
		}
		if(w==1)printf("NO\n");
		else
		 printf("YES\n");
	}
	return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <queue>

using namespace std;

int main() {

	int n;
	int num[10];
	int min_A = 0, min_B = 0;
	int pos;

	while (cin >> n)
	{
		while (n-- > 0)
		{
			for (int i = 0; i < 10; i++)
			{
				cin >> num[i];
			}
			for ( pos = 0; pos < 10; pos++)
			{
				if (num[pos] > min_A)
				{
					min_A = num[pos];
				}
				else if (num[pos] > min_B)
				{
					min_B = num[pos];
				}
				else
				{
					break;
				}
			}
			if (pos == 10)
			{
				cout << "YES" << endl;
			}
			else
			{
				cout << "NO" << endl;
			}
		}

	}
	return 0;
}

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;
        }
        printf("%s\n", f ? "No" : "Yes");

    }

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10;
int num[N];
bool dfs(int i,int a,int b){
	if(i == N)	return true;
	if(num[i] > a)	if(dfs(i+1,num[i],b))	return true;
	if(num[i] > b)	if(dfs(i+1,a,num[i]))	return true;
	return false;
}
bool solve(){ return dfs(0,-1,-1); }
int main(){
	int T;	scanf("%d",&T);
	while(T--){
		for (int i = 0; i < N; ++i)	scanf("%d",num+i);
		if(solve())	puts("YES");
		else		puts("NO");
	}
}