Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int A[10];
vector<int> B, C;
int N;

void solve() {
  B.clear();
  C.clear();
  for (int i = 0; i < 10; i++) {
    int k = A[i];
    if (B.empty()) {
      B.push_back(k);
      continue;
    }
    if (C.empty()) {
      C.push_back(k);
      continue;
    }
    int m = max(k - B.back(), k - C.back());
    if (m <= 0) {
      printf("NO\n");
      return;
    }
    if (m == k - B.back())
      C.push_back(k);
    else
      B.push_back(k);
  }
  printf("YES\n");
}

int main() {
  scanf("%d", &N);
  while (N--) {
    for (int i = 0; i < 10; i++) scanf("%d", &A[i]);
    solve();
  }
}

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.top() < x) {
				l.push(x);
				continue;
			}
			if (r.size() == 0 || r.top() < x) {
				r.push(x);
				continue;
			}
			cout << "NO" << endl;
			goto yarudake;
		}
		cout << "YES" << endl;
yarudake:;
	}
}

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

int B[11]={0};
int C[11]={0};

bool DFS(int *a,int i=0,int b=1,int c=1)
{
	bool judge=true;

	if(i==10)
		return judge;

	judge=false;

	if(B[b-1]<a[i]){
		B[b]=a[i];
		judge=DFS(a,i+1,b+1,c);
		
	}
	if(C[c-1]<a[i]){
		C[c]=a[i];
		judge=DFS(a,i+1,b,c+1);
		
	}

	return judge;
}        

int main()
{
        int N;
	int i=0;
        cin>>N;

		while(i<N){
			int A[10]={0};
			for(int i=0;i<10;i++)
				cin>>A[i];

            ??????????????????if(DFS(A)==true)
                ????????????????????????cout<<"YES"<<endl;
            ??????????????????else
		????????????????????????cout<<"NO"<<endl;

	????????????????????????i++;
        }
                
	
        return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
void dfs(int b[10],int c[10],int m,int k,int t);//a中，b中，c中游标
int a[10];
int flag;
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		int b[10];
		int c[10];
		b[0] = 0;
		c[0] = 0;
		flag = 0;
		dfs(b, c, 0, 0, 0);
		if (flag== 1)
			cout << "YES" << endl;
		else 
			cout << "NO" << endl;
	}
	return 0;
}
void dfs(int b[10], int c[10], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[10], y[10];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		flag=1;
	for (i = 0; i <=kb; i++)
	{
		x[i] = b[i];	
	}
	for (i = 0; i <= tc; i++)
	{
        y[i] = c[i];
	}
	/*if (x[kb] > a[ma] && y[tc] > a[ma])  //两个都大  不要直接return 应该返回 找其他的枝丫
		return 0;*/
	if (x[kb] > a[ma] && y[tc] < a[ma])
	{
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] > a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
	if (x[kb] < a[ma] && y[tc] < a[ma])
	{
		x[kb] = a[ma];
		ma++; kb++;
		if (ma <=10)
			dfs(b, c, ma, kb, tc);
		ma--; kb--;
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
	}
}

C++: #include <iostream>
using namespace std;
int N;
int num[10];
int number;
void solve(){
	cin>>N;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<10;j++)
		cin>>num[j];
		number=num[0];
		num[0]=0;
		for(int j=1;j<10;j++)
		{
			if(num[j]==number+1)
			{
				number=num[j];
				num[j]=0;
			}
		}
		number=0;
		int flag=1;
		for(int j=1;j<10;j++)
		{
			if((number==0)&&(num[j]!=0))
			{
				number=num[j];
				continue;
			}
			else{
				if(num[j]!=0)
				{
					if(num[j]>number)
					{
						number=num[j];
					}
					else{
				        cout<<"NO"<<endl;
				        flag=0;
				        break;
				    }
				}
			}
		}
		if(flag==1) cout<<"YES"<<endl;
	}
}
int main(){
	solve();
}

C++: #include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<int(n);i++)
int a[10];
int main(){
	int t;
	cin>>t;
	while(t--){
		forn(i,10) cin>>a[i];
		int fi=0,se=0;
		bool b=true;
		forn(i,10){
			if(fi<a[i]&&se<a[i]){
				if(fi<=se) se=a[i];
				else fi=a[i];
			}
			else if(fi<a[i]) fi=a[i];
			else if(se<a[i]) se=a[i];
			else{
				b=false;
				break;
			}
		}
		if(b) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<int> A = {-1};
vector<int> B = {-1};
int num[10];
bool flag = false;
void push(int i)
{
	if (i == 10)
		flag = true;
	else
	{
		if (A.back() < num[i])
		{
			A.push_back(num[i]);
			push(i + 1);
			A.pop_back();
		}
		if (B.back() < num[i])
		{
			B.push_back(num[i]);
			push(i + 1);
			B.pop_back();
		}
	}
}
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		flag = false;
		for (int i = 0; i <= 9; ++i)
			cin >> num[i];
		push(0);
		if (flag == true)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
using namespace std;
const int MAXN = 40;

int p[10], pre1, pre2;

bool dfs(int pos) {
    if (pos >= 10) return true;
    int tmp1 = pre1, tmp2 = pre2;

    if (p[pos] > pre1) {
        pre1 = p[pos];
        if (dfs(pos + 1)) return true;
        pre1 = tmp1;
    }

    if (p[pos] > pre2) {
        pre2 = p[pos];
        if (dfs(pos + 1)) return true;
        pre2 = tmp2;
    }

    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        for (int i = 0; i < 10; i++) cin >> p[i];
        pre1 = pre2 = -1;
        if (dfs(0)) cout << "YES\n";
        else cout << "NO\n";
    }
}