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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(all(v),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int l=0,r=0,a,N;
  cin >> N;
  rep(i,N){
    bool f = false;
    vary(int,v,10,0);
    rep(i,10){
      cin >> v[i];
    }
    queue<pair<pii,int>> q;
    q.push(make_pair(make_pair(0,0),0));
    while(!q.empty()){
      auto top = q.front();q.pop();
      if(top.se == 10){
        f = true;
        break;
      }
      l = top.fi.fi,r=top.fi.se;
      a = v[top.se];
      if(r < a){
        r = a;
        q.push(make_pair(make_pair(l,r),top.se+1));
      }
      else if(l < a){
        l = a;
        q.push(make_pair(make_pair(l,r),top.se+1));
      }
    }
    Ans(f);
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

void chmax(int& a,int b){
	if(b > a){
		a=b;
	}
}
string j(){
	int d1=0,d2=0;
	rep(j,10){
		int n;
		cin >> n;
		if(d1<n){
			d1=n;
			continue;
		}else{
			if(d2<n){
				d2=n;
				continue;
			}else{
				return "NO";
			}
		}
	}
	return "YES";

}
int main(){
	int N;
	cin >> N;
	rep(i,N){
		cout << j() << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

int n,x[10];
int b,c;
char t;
bool flag=true;

int main(){
	cin>>n;
	rep(i,n){
		flag = true;
		b = c = -1;
		rep(j,10) cin>>x[j];
		rep(j,10){
			if(x[j]<min(b,c)){
				flag = false;
				break;
			}
			if(x[j]<b) c = x[j];
			else if(x[j]<c) b = x[j];
			else if(b<c) c = x[j];
			else b = x[j];
			//cout<<b<<" "<<c<<endl;
		}
		if(flag) cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int a[10];
bool dfs(int i,int j,int k){
	return(k==10||(i<a[k]&&dfs(a[k],j,k+1))||(j<a[k]&&dfs(i,a[k],k+1)));
}
int main() {
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++)cin>>a[j];
		cout<<(dfs(0,0,0)?"YES":"NO")<<endl;
	}
}

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

int main(){
	int ball[10];
	int cell[2][5];
	int n,i,k,j=0,flag=0;
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
	
	for(i=0;i<10;i++)scanf("%d",&ball[i]);
	for(i=0;i<10;i+=2){cell[0][j]=ball[i]; j++;}
		j=0;
	for(i=1;i<10;i+=2){cell[1][j]=ball[i]; j++;}
		j=0;
	for(i=0;i<4;i++){
		if(cell[0][i] > cell[0][i+1] || cell[1][i] > cell[1][i])flag=1;
		else flag=0;
	}
	if(flag==0)printf("YES\n");
	else printf("NO\n");
	
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int N,m;
  cin>>N;
  while(N--){
    int B,C=0,i=0;
    bool f=true;
    cin>>B;
    while(++i<10){
      cin>>m;
      if(B<m){
	if(B<C&&C<m)C=m;
	else B=m;
      }else if(C<m){
	C=m;
      }else{
	f=false;break;
      }
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}

C++: #include<cstdio>
int main(){
    int n;
    int s;
    int a[10];
    bool check[10];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            scanf("%d",&a[j]);
            check[j]=false;
        }
        s=0;
        for(int j=0;j<10;j++){
            for(int k=j+1;k<10;k++){
                if(a[j]<a[k] && !check[j] && !check[k]){
                    check[j]=check[k]=true;
                    s++;
                }
            }
        }
        if(s>=2) printf("YES\n");
        else printf("NO\n");
    }
}

C++: #include<iostream>

int ball[10];
bool res;

void dfs(int i, int ls, int rs){
	if (i == 10){
		res = true;
		return;
	}

	if (ball[i] > ls)dfs(i + 1, ball[i], rs);
	if (ball[i] > rs)dfs(i + 1, ls, ball[i]);
}

int main(){
	int n;
	std::cin >> n;

	for (int i = 0; i < n; i++){
		for (auto &i : ball)std::cin >> i;
		res = false;
		dfs(0, 0, 0);
		std::cout << (res ? "YES" : "NO") << std::endl;
	}
	return 0;
}