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<array>
#include<vector>
using namespace std;

array<int, 10> ary;
vector<int> lf, rt;

int main(){
	bool dfs(int );
	
	
	int n;
	scanf("%d", &n);
	for(int i  = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			int t;
			scanf("%d", &t);
			ary[j] = t;
		}
		lf.clear();
		rt.clear();
		if(dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
} 

bool dfs(int i){
	if(i == 9){
		if(lf.size() == 0 || rt.size() == 0) return true;
		else if(ary[i] > *lf.rbegin() || ary[i] > *rt.rbegin()) return true;
		else return false;
	}
	lf.push_back(ary[i]);
	if(lf.size() == 1 || lf[lf.size() - 1] > lf[lf.size() - 2]) return dfs(i+1);
	lf.pop_back();
	rt.push_back(ary[i]);
	if(rt.size() == 1 || rt[rt.size() - 1] > rt[rt.size() - 2]) return dfs(i+1);
	return false;
}

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

int balls[10];

bool dfs(int left, int right, int currentID){
	if(currentID > 9) return true;
	
	bool ok = false;
	if (left < balls[currentID]){
		ok = dfs(balls[currentID], right, currentID+1);
	}
	if (right < balls[currentID]){
		ok = dfs(left, balls[currentID], currentID+1);
	}
	return ok;
}

int main() {
	int n; cin >> n;
	
	while(n--){
		for (int i = 0; i < 10; i++) cin >> balls[i];
		cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
	}
}

C++: #include<cstdio>
#include<cstring>
const int MAX_N = 15;
int x[MAX_N],l[MAX_N],r[MAX_N];
int kase;
void dfs(int i,int j,int k)
{
	if(i>10)
	{
		kase=1;
		return;
	}
	if(kase)
	{
		return;
	}
	if(x[i]>l[j-1])
	{
		l[j]=x[i];dfs(i+1,j+1,k);
	}
	if(x[i]>r[k-1])
	{
		r[k]=x[i];dfs(i+1,j,k+1);
	}
}
int main()
{
	int t; 
	scanf("%d",&t);
	while(t--)
	{
		for(int i=1;i<=10;++i)
		{
			scanf("%d",&x[i]);
		}
		kase=0;
		dfs(1,1,1);
		if(kase)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

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

int main(){
	int N;
	int A[10];
	int cnt1=0;
	cin>>N;
	while(1){
		
		if(cnt1==N){
			break;
		}
		cnt1++;
		for(int i=1;i<=10;i++){
			cin>>A[i];
		}
		int B=A[1];
		int C=0;
		int cnt2=0;
		int cnt3=2;
		for(int i=2;i<=10;i++){
			if(B+1==A[i]){
				B=A[i];
				cnt2++;
			}
			else if(C<A[i]){
				C=A[i];
				cnt2++;
			}
			
			cnt3++;	
		}
		if(cnt2==9){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;	
}

C++: #include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
#define MAXN 10005
using namespace std;
int num[10];
int numl[10],numr[10];
bool charge[10];
int main()
{
   int n;
     scanf("%d",&n);
   while(n--){
    for(int i=0;i<10;i++)
    {
      scanf("%d",&num[i]);
      charge[i]=false;
    }
    int left=num[0],right=0,count1=1;
     charge[0]=true;
    for(int j=1;j<10;j++)
    {
       if(!charge[j]&&num[j]>left)
        {
         left=num[j];
         count1++;
         charge[j]=true;
        }
    }
     for(int j=0;j<10;j++)
    {
       if(!charge[j]&&num[j]>right)
        {
         right=num[j];
         count1++;
         charge[j]=true;
        }
    }
    if(count1!=10) printf("NO\n");
    else printf("YES\n");
   }
    return 0;
}

C++: #include <iostream>

using namespace std;
int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; ++i){
		//read input data and test it
		bool ok = true;
		int a, b;
		a = b = 0;
		for(int j = 0; j < 10; ++j){
			int c;
			cin >> c;
			if(b > c){
				ok = false;
			}else if(a > c){
				b = c;
			}else{
				a = c;
			}
		}
		if(ok){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

C++: #include <cstdio>
#include <list>

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0,tmp;i<n;i++){
		list<int> a,b,c;
		for(int j=0;j<10;a.push_back(tmp),j++)
			scanf("%d",&tmp);
		while(!a.empty()){
			if(a.front()>b.back()||b.empty()){
				b.push_back(a.front());
				a.pop_front();
			}
			else if(a.front()>c.back()||c.empty()){
				c.push_back(a.front());
				a.pop_front();
			}
			else break;
		}
		puts(a.empty()?"YES":"NO");
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int b = 0 ,c = 0;
  cin >> n;
  while(n--){
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b < a)b = a;
      else if(c < a)c = a;
      else {
	cout << "NO" << endl;
	return 0;
      }  
    }
    cout << "YES" << endl;
  }
  return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const LL INF = 1e18;


int main(){
	int n;
	cin>>n;
	REP(i,n){
		int num[10];
		REP(j,10)cin>>num[j];
		bool flag;
		REP(j,1023){
			bitset<10>bs(j);
			int n1=0,n2=0;
			flag=true;
			REP(k,10){
				if(bs[k]==0){
					
					if(n1<num[k])n1=num[k];
					else{
						flag=false;
						break;
					}
				}else{
					if(n2<num[k])n2=num[k];
					else{
						flag=false;
						break;
					}
				}
			}
			if(flag)break;
		}
		if(flag){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}
/*

*/

C++: #include <iostream>
using namespace std;
int n, a[10];

bool dfs(int b, int c, int cnt) {
	bool ans = false;
	if (cnt == 10) {
		return true;
	}
	if (b < a[cnt]) {
		ans = dfs(a[cnt], c, cnt + 1);
	}
	if (c < a[cnt]) {
		ans = dfs(b, a[cnt], cnt + 1);
	}
	return ans;
}

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