Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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) {
				if (l.top() < x) {
					l.push(x);
					continue;
				}
				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<iostream>
int main() {
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i += 1) {
		int N[10];
		for (int i = 0; i < 10; i += 1) 
			std::cin >> N[i];
		if (N[0] == 1 || N[1] == 1)
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}
	return 0;
}

C++: #include <stdio.h>
??
#define NUM_BALL 10
??
int main(void)
{
????int???????????? n;
????int???????????? num;
????int???????????? left, right;
????int?? flag = 1;
????int???? i, j;
??
????scanf("%d", &n);
????for (i = 0; i < n; i++) {
????????????????left = right = -1;
????????????????for (j = 0; j < NUM_BALL; j++) {
????????????????????????scanf("%d", &num);
????????????????????????if?????????? (num > left) { left?? = num; }
????????????????????????else if (num > right)?????? { right = num; }
????????????????????????else?????? { flag?? = 0; break; }
????????????????}
????????????????puts((flag) ? "YES" : "NO");
????????}
??
????????return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;


int a[10];
int n;

bool dfs(int i,int left, int right){
    if(i==10) return true;
    if(a[i]>left){
        if(dfs(i+1,a[i],right)) return true;
    }
    if(a[i]>right){
        if(dfs(i+1,left,a[i])) return true;
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        solve();
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
int a[10];
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        for(int i=0;i<10;i++){
            scanf("%d",&a[i]);
        }
        int w=0;
        int now=0;
        for(int i=0;i<10;i++){
            if(a[i]>now){
                now=a[i];
                a[i]=0;
                w++;
            }
        }
        now=0;
        for(int i=0;i<10;i++){
            if(a[i]>now){
                now=a[i];
                a[i]=0;
                w++;
            }
        }
        printf("%s\n",w==10?"YES":"NO");
    }
    return 0; 
}

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


bool vis[15];
int a[15];

bool ok = false;


void dfs(int cnt, int last){
	if(cnt == 9){
		vector<int> ver;
		for (int i = 0; i < 10; i++){
			if(!vis[i]){
				ver.push_back(a[i]);
			}
		}
		bool flag = true;
		for (int i = 1; i < ver.size(); i++){
			if(ver[i] < ver[i - 1]){
				flag = false;
			}
		}
		if(flag){
			ok = true;
		}
		return;
	}
	for (int i = cnt; i < 10; i++){
		if(a[i] > last){
			vis[i] = true;
			dfs(i + 1, a[i]);
			vis[i] = false;
		}
	}
	return;
}
 





int main(){
	int n;
	cin >> n;
	while(n--){
		ok = false;
		memset(a, 0, sizeof(a));
		memset(vis, 0, sizeof(vis));
		for (int i = 0; i < 10; i++){
			cin >> a[i];
		}
		
		dfs(0, 0);
		if(ok){
			cout << "YES" << endl;
		}else cout << "NO" << endl; 
		
		
		
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int ball[100][10],count=0;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ball[i][j];
    }
    for(int j=0;j<6;j++){
      if(ball[i][j] > ball[i][j+2] || ball[i][j+1] > ball[i][j+3]){
	cout << "NO" << endl;
	  count++;
	  break;
      }
    }
    if(count == 0){
      cout << "YES" << endl;
    }
  }
}

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

int a[10];

int main() {
	int T;
	cin >> T;
	while (T--) {
		bool ans = true;
		for (int i = 0; i < 10; ++i) {
			cin >> a[i];
		}
		int l, r;
		l = r = 0;
		for (int i = 0; i < 10; ++i) {
			if (a[i] > l) {
				l = a[i];
			} else if (a[i] > r) {
				r = a[i];
			} else {
				and = false;
				break;
			}
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}

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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		bool flag = false;
		int prev;
		int in[10];
		int used[10];
		for (int j = 0; j < 10; j++)
		{
			cin >> in[j];
		}
		prev = in[0];
		vector<int> B;
		vector<int> C;
		for (int j = 0; j < 10; j++)
		{
			if (prev > in[j])
			{
				C.push_back(in[j]);
				used[j] = false;
				continue;
			}
			else
			{
				prev = in[j];
				B.push_back(in[j]);
				used[j] = true;
			}
		}
		prev = C[0];
		for (int j = 0; j < C.size(); j++)
		{
			if (prev > C[j])
			{
				flag = true;
				break;
			}
			else
			{
				prev = C[j];
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}