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 <iostream>
#include <cstdio>
using namespace std;

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int t;
    cin>>t;
    while(t--){
        int ball[10];
        for(int i=0;i<10;i++){
            cin>>ball[i];
        }

        int left=0;
        int right=0;

        bool ok=true;
        bool direction=true;
        while(ok){
            for(int i=0;i<10;i++){
                if(direction){
					
                    if(ball[i]>left){
                        left=ball[i];
                        direction=!direction;
                    }
					
                    else{
                        ok=false;
                        break;
                    }
                }

                else{

                    if(ball[i]>right){
                        right=ball[i];
                        direction=!direction;
                    }

                    else{
                        ok=false;
                        break;
                    }
                }
            }
            break;
        }

        if(ok) cout<<"YES";
        else cout<<"NO";
        if(t) cout<<endl;
    }

    return 0;
}

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

using namespace std;

int main() {

	int j, n, end=0;
	stack<int> B, C;
	int A[10];

	cin >> n;
	for(; n!=0; n--) {
		for(int i=0; i<10; i++) {
			cin >> A[i];
		}
		B.push(0);
		C.push(0);
		for(int i=0; i<10; i++) {
			j=A[i];
			if(B.top()==0)
				B.push(j);
			else {
				if(B.top()>j) {
					if(C.top()>j) {
						end++;
						break;
					}
					else 
						C.push(j);
				}
				else {
					if(C.top()>j)
						B.push(j);
					else
						(j-B.top()>j-C.top()) ? C.push(j) : B.push(j);
				}
			}
		}

		if (end!=0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
		end=0;
	}

	return 0;

}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int N,i,a,j,s,t,u;
	cin >> N;
	for (i = 0; i < N; i++) {
		s = 0;
		t = 0;
		u = 0;
		for (j = 0; j < 10; j++) {
			cin >> a;
			if (a > s) {
				s = a;
			}
			else if (a<s&&a>t) {
				t = a;
			}
			else if (a < s&&a < t) {
				u = 1;
			}
		}
		if (u == 0) {
			cout << "YES" << endl;
		}
		else if (u == 1) {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  while(n--) {
    int a[10],b=0,c=0,i;
    for(i=0; i<10; i++) cin >> a[i];
    for(i=0; i<10; i++) {
      if(a[i]>b && a[i]>c) {
	if(b>c) b=a[i];
	else c=a[i];
      }
      else if(a[i]>b && a[i]<c) b=a[i];
      else if(a[i]<b && a[i]>c) c=a[i];
      else break;
    }
    if(i==10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<iostream>

using namespace std;

int N;
int num[10];
bool flag = false;

void dfs(int a, int b, int cnt){
    if(cnt==10) flag = true;
    if(a < num[cnt]) dfs(num[cnt], b, cnt+1);
    if(b < num[cnt]) dfs(a, num[cnt], cnt+1);
}

int main(){
    scanf("%d\n", &N);
    for(int i=0; i<N; i++){
        flag = false;
        for(int j=0; j<10; j++) scanf("%d", num+j);
        dfs(0,0,0);
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    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(x, y, ma, kb, tc);
		ma--; kb--;
		y[tc] = a[ma];
		ma++; tc++;
		if (ma <=10)
			dfs(x, y, ma, kb, tc);
		ma--; tc--;
	}
}

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

void DFS(int* arr, int pos, int* res, int index, bool& flag) {
	if (pos >= 10||flag)
	{
		return;
	}
	if ((index==0) || (index >= 1 && res[index - 1] < arr[pos]))
	{
		res[index] = arr[pos];
		arr[pos] = 0;
	}
	DFS(arr, pos+1, res, index+1, flag);
	if (flag)
	{
		return;
	}
	int pre = 0;
	int cur = 0;
	flag = true;
	for (int i = 0; i < 10; i++)
	{
		if (arr[i]!=0)
		{
			pre = pre == 0 ? arr[i] : cur;
			cur = arr[i];
			if (cur < pre)
			{
				flag = false;
				break;
			}
		}
	}
}

int main()
{
	int N, arr[11], res[10];
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cin >> arr[j];
		}
		bool flag = false;
		DFS(arr, 0, res, 0, flag);
		if (flag)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

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

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v{ {0} };
		for (int j = 0; j < 10; j++) {
			cin >> x;
			z = v.size();
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v.push_back({ x });
					break;
				}
			}

			if (v.size() == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue< pair<int, int> > qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vpii;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int n[10];
int h, w;
int b,c;

bool dfs(int cnt) {
  if(cnt == 10) return true;
  if(n[cnt] > n[b]) {
    int tmp = b;
    b = cnt;
    if(dfs(cnt+1)) return true;
    b = tmp;
  }
  if(n[cnt] > n[c]) {
    int tmp = c;
    c = cnt;
    if(dfs(cnt+1)) return true;
    c = tmp;
  }
  return false;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

  int num;
  cin >> num;
  rep(i,0,num) {
    rep(j,0,10) cin >> n[j];
    b = 0;
    c = 1;

    if(dfs(2)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

	return 0;
}