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++: // 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 <bits/stdc++.h>
using namespace std;

int main(){
	int T;
	cin >> T;
	while(T--){
		int a=0,b=0;
		string ans = "YES";
		for(int i = 0 ; i < 10 ; i++){
			if( a > b ) swap(a,b);
			int x;
			cin >> x;
			if( x < a ){
				ans = "NO";
			}else if( b < x ){
				b = x;
			}else{
				a = x;
			}
		}
		cout << ans << endl;
	}
	
}

C++: #include<stdio.h>
int a[10];
int bstack[10];
int btop;
int cstack[10];
int ctop;
bool dfs(int i)
{
    bool b1=false,b2=false;
    if(i==10)
        return true;
    if(btop==-1 || bstack[btop]<a[i])
    {
        btop++;
        bstack[btop]=a[i];
        i++;
        b1=dfs(i);
        btop--;
    }
    if(ctop==-1 || cstack[ctop]<a[i])
    {
        ctop++;
        cstack[ctop]=a[i];
        i++;
        b2=dfs(i);
        ctop--;
    }
    return b1||b2;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        for(int i=0;i<10;i++)
        {
            scanf("%d",&a[i]);
        }
        btop=-1;
        ctop=-1;
        if(dfs(0))
            printf("YES\n");
        else
            printf("NO\n");
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a;
  srand((unsigned)time(NULL));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a;
    }
    if(rand()%2==0){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
int a[11];
int a1[11];
int pn=0;
int Flag;
void dfs(int i)
{
    if(Flag==1)
        return;

    if(a[i]>a[a1[pn]])
    {
        a1[++pn]=i;
        for(int m=i+1;m<=10;m++)
        {
            dfs(m);
        }
    }
    else
        return;
    int flag=0;
    for(int m=i+1;m<=10;m++)
    {
        if(a[m]>a[i])
            flag=1;
    }
    int flag2;
    if(flag==0||i==10)
    {
        int a2[11];
        int pm=0;
        for(int n=1;n<=10;n++)
        {
            flag2=0;
            for(int m=1;m<=pn;m++)
            {
                if(n==a1[m])
                   flag2=1;
            }
            if(!flag2)
            {
               a2[++pm]=n;
            }
        }
        int flag3=0;
        for(int m=1;m<pm;m++)
        {
            if(a[a2[m]]>a[a2[m+1]])
                flag3=1;
        }
        if(flag3==0)
        {
            Flag=1;
            return;
        }
        else
        {
            pn--;
            return;
        }
    }

}
int main()
{
    int n;
    
    scanf("%d",&n);
    getchar();
    a[0]=-1;
    a1[0]=0;
    for(int i=1;i<=n;i++)
    {
        Flag=0;
        pn=0;
        for(int j=1;j<=10;j++)
        {
            scanf("%d ",&a[j]);
        }
        dfs(1);
        if(Flag==0)
        {
            printf("NO\n");
        }
        else
            printf("YES\n");
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
    int a[20],b[20],c[20];
    int n;
    cin >> n;
    while (n--)
    {
        bool judge = true;
        for (int i = 1; i <= 10; ++i)
            cin >> a[i];
        int cb = 1,cc = 1;
        b[cb++] = a[1],c[cc++] = a[2];
        for (int i = 3; i <= 10; ++i)
        {
            int cha1 = a[i] - b[cb-1];
            int cha2 = a[i] - c[cc-1];
            if (cha1 < 0 && cha2 < 0)
            {
                judge = false;
                break;
            }
            if (cha1 < 0)
                c[cc++] = a[i];
            if (cha2 < 0)
                b[cb++] = a[i];
            if (cha1 < cha2)
                b[cb++] = a[i];
            else c[cc++] = a[i];
        }
        if (judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: /******************************************
    > File Name: Aoj_0033.cpp
    > Author: universal42
    > Mail: universal42@163.com 
    > Created Time: 2019年05月03日 星期五 16时38分31秒
 ******************************************/

#include<bits/stdc++.h>
#define ll long long int
#define inf 0x3f3f3f3f
#define LOCALa
using namespace std;
const int maxn=1e5+5;
int n;
int arr[10],a[10],b[10];
int flag=0;
void dfs(int i,int j){
	if(flag){
		return;
	}
	if(i+j==10){
		for(int p=0;p<i-1;p++){
			if(a[p]>a[p+1]){
				return;
			}
		}
		for(int p=0;p<j-1;p++){
			if(b[p]>b[p+1]){
				return;
			}
		}
		flag=1;
		return;
	}
	a[i]=arr[i+j];
	dfs(i+1,j);
	b[j]=arr[i+j];
	dfs(i,j+1);
}
void solve(){
	scanf("%d",&n);
	while(n--){
		flag=0;
		for(int i=0;i<10;i++){
			scanf("%d",&arr[i]);
		}
		dfs(0,0);
		if(flag){
			puts("YES");
		}
		else{
			puts("NO");
		}
	}
}
int main(){
#ifdef LOCAL
    freopen("in.in","r",stdin);
#endif
    solve();
    return 0;
}

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

int main() {
	int n, x;
	cin >> n;

	for (int i = 0; i++ < n;) {
		int hole[2] = { 0 };
		for (int j = 0; j < 10; j++) {
			cin >> x;

			if (hole[0] < x) {
				hole[0] = x;
			}else if (hole[1] < x) {
				hole[1] = x;
			} else {
				cout << "NO";
				break;
			}

			if (j == 9) {
				cout << "YES";
			}
		}
		cout << endl;
	}
	return 0;
}