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 <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;
}

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

int B[12], C[12], num[12], b, c;

bool dfs(int b, int c, int i){
    if(i == 10) return true;
    B[b+1] = num[i];
    C[c+1] = num[i];
    if(B[b]<num[i] && dfs(b+1, c, i+1)){
        return true;
    }
    if(C[c]<num[i] && dfs(b, c+1, i+1)){
        return true;
    }
    return false;
}

int main(void){
  int N;
  cin >> N;
  for(int j=0; j<N; j++){
  B[0] = 0;
  C[0] = 0;
  for(int i=0; i<10; i++){
    cin >> num[i];
  }
  dfs(0, 0, 0);
  if(dfs(0, 0, 0))  cout << "YES" << endl;
  else cout << "NO" << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int a[10],b=0,c=0;
bool tube[10];
bool dfs(int i){
    if(i==10) return true;
    bool flagb,flagc;
    if(b>=a[i]&&c>=a[i]) return false;
    if(b<a[i]){
        int oldb=b;
        b=a[i];
        flagb=dfs(i+1);
        b=oldb;
        if(flagb) return true;
    }
    if(c<a[i]){
        int oldc=c;
        c=a[i];
        flagc=dfs(i+1);
        c=oldc;
        if(flagc) return true;
    }
    return flagb||flagc;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            scanf("%d",a+j);
        }
        if(dfs(0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

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

stack<int> array1,array2;
int Balls[10];

bool DFS(int number,stack<int> s1,stack<int> s2){
  if(number > 9) return true;
  if(s1.top() < Balls[number]){
    s1.push(Balls[number]);
    if(DFS(number+1,s1,s2)){
      return true;
    }
    s1.pop();
  }
  if(s2.top() < Balls[number]){
    s2.push(Balls[number]);
    if(DFS(number+1,s1,s2)){
      return true;
    }
    s2.pop();
  }
  return false;
}

int main(){

    int N;

    cin >> N;

    for(int i=0;i<N;i++){
      for(int i=0;i<10;i++){
        cin >> Balls[i];
      }
      array1.push(0);
      array2.push(0);

      if(DFS(0,array1,array2)){
        cout << "YES" << endl;
      }
      else{
        cout << "NO" << endl;
      }
      while (!array1.empty()) {
        array1.pop();
      }
      while (!array2.empty()) {
        array2.pop();
      }
    }
    return 0;
}