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 <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;
typedef long long ll;


int a[10];

bool put(int cur,int lt, int rt) {
	if (cur == 10)
		return true;
	if (a[cur] < lt && a[cur] < rt)
		return false;
	bool lres= false,rres=false;
	if( a[cur] > lt) {
		lres = put(cur + 1, a[cur], rt);
	}
	if( a[cur] > rt) {
		rres = put(cur + 1, lt, a[cur]);
	}
	if (lres || rres)
		return true;
	else
		return false;
}

int main() {
	int T;
	cin >> T;
	for (int t = 0; t < T; t++) {
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
		}
		if (put(0, 0, 0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int a[10];
bool ans;

void dfs(int idx, int l, int r) {
   if (idx == 10) {
      ans = true;
      return;
   }

   int val = a[idx];
   if (l < val) dfs(idx+1, val, r);
   if (r < val) dfs(idx+1, l, val);
}

int main() {
   int N;
   cin >> N;
   while (N--) {
      for (int i = 0; i < 10; i++) {
         cin >> a[i];
      }
      ans = false;
      dfs(0, -1, -1);
      puts(ans ? "YES" : "NO");
   }

   return 0;
}

C++: #include <iostream>

using namespace std;

int main(void) {
    int N, a, b, c, x[10];
    cin >> N;
    for (; N--; ) {
        bool ok = true;
        for (int i = 0; i < 10; i++) {
            cin >> x[i];
        }
        b = c = 0;
        for (int i = 0; i < 10; i++) {
            a = x[i];
            if (a < b && a < c) {
                ok = false;
                break;
            } else if (a < b) {
                c = a;
            } else if (a < c) {
                b = a;
            } else if (b < c) {
                c = a;
            } else {
                b = a;
            }
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <stdio.h>

#include <stack>

int main(void){
    using namespace std;
    stack<int> a,b;
    int n,j,i,ball,flag;
    scanf("%d",&n);
    for(j=0; j<n; j++){
        flag=0;
        for(i=0; i<10; i++){
            scanf("%d",&ball);
            if(a.empty()){
                a.push(ball);
            }else if(a.top() < ball){
                a.push(ball);
            }else if(b.empty()){
                b.push(ball);
            }else if(b.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        while(!a.empty()){
            a.pop();
        }
        while(!b.empty()){
            b.pop();
        }
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

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

using namespace std;

int main() {
	vector<int> left;
	vector<int> right;
	vector<int> all;

	bool flag = true;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			int temp;
			cin >> temp;
			all.push_back(temp);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			if (left.size() > 0) {
				if (all[10 * i + j] > left[left.size() - 1]) {
					left.push_back(all[10 * i + j]);
				}
				else {
					if (right.size() > 0) {
						if (all[10 * i + j] > right[right.size() - 1])
							right.push_back(all[10 * i + j]);
						else
							flag = false;
					}
					else {
						right.push_back(all[10 * i + j]);
					}
				}
			}
			else {
				left.push_back(all[10 * i + j]);
			}
		}

		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO"<<endl;
		flag = true;
	}

	return 0;
}

C++: //C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;


using namespace std;
int main(){
    int N;
    cin>>N;
    
    for(int i=0;i<N;i++){
        stack<int> a,b;
        a.push(0);
        b.push(0);
        bool flag=true;
        for(int j=0;j<10;j++){
            int tm;
            cin>>tm;
            if(tm>a.top()) a.push(tm);
            else if(tm>b.top()) b.push(tm);
            else {flag=false;}
        }
        if(flag)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
};

C++: #include<iostream>
using namespace std;
int r[11],l[11],t[11];
int kyes;

void dfs(int i,int j,int k)//j->left,k->right
{
    if(i>10)
    {
        kyes=1;
    }
    if(kyes)
    return;
    if(t[i]>l[j-1])
    {
        l[j]=t[i];
        dfs(i+1,j+1,k);
    }
    if(t[i]>r[k-1])
    {
        r[k]=t[i];
        dfs(i+1,j,k+1);
    }
}
int main()
{
    int i;
    int n;
    cin>>n;
    while(n--)
    {
        for(i=1; i<=10; i++)
            cin>>t[i];
        kyes=0;
        dfs(1,1,1);
        if(kyes)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;

bool ok(vi a) {
	FOR(i, 1, a.size()-1) {
		if(a[i-1] > a[i]) {
			return false;
		}
	}
	return true;
}

int main() {
	int N;
	cin >> N;

	REP(sgz, N) {
		vi a, b;

		int x;
		cin >> x;
		a.push_back(x);
		REP(i, 9) {
			cin >> x;
			if(x > a[a.size()-1]) {
				a.push_back(x);
			} else {
				b.push_back(x);
			}
		}

		if(ok(a) && ok(b)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>

int main(){
int n,i,j;
int a,b,c;

scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a);
b=0;
f=0;
for(j=1;j<10;j++){
scanf("%d",&c);
if(a>c&&b>c)f=1;
else if(a<c&&b<c){
if(a>b)a=c;
else b=c;
}
else{
if(a>b)b=c;
else a=c;
}
}
if(f==0){
printf("YES\n");
}
else if(f==1){
printf("NO\n");
}
}
return 0;
}