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++: a[10];int dfs(int l,int r,int i){if(i>9)return 1;if(a[i]>l&&dfs(a[i],r,i+1))return 1;if(a[i]>r&&dfs(l,a[i],i+1))return 1;return 0;
}main(n){scanf("%d",&n);for(;n;n--)scanf("%d%d%d%d%d%d%d%d%d%d",a+0,a+1,a+2,a+3,a+4,a+5,a+6,a+7,a+8,a+9),dfs(0,0,0)?puts("YES"):puts("NO");return 0;}

C++: #include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int bmax[10],cmax[10];
int main() {
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        int ball[10]={};
        int ans=0;
        for(int j=0; j<10; j++){
            cin>>ball[j];
        }
        for(int s=2; s<10; s++){
            for(int t=0; t<s; t++){
                if(ball[s]>ball[t]){
                    ans++;
                    break;
                }
            }
        }
        if(ans==8) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int n;
int a[15],b[15],c[15];
int flag;
void dfs(int i,int j,int x)
{
    if(i + j == 12){
        flag = 1;
        return ;
    }
    if(flag == 1)
        return ;
    if(a[x] > b[i - 1]){
        b[i] = a[x];
        dfs(i + 1,j,x + 1);
    }
    else
    {
        if(a[x] > c[j - 1]){
            c[j] = a[x];
            dfs(i,j + 1,x + 1);
        }
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        while(n --){
            for(int i = 0; i < 10; i++)
                scanf("%d",&a[i]);
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            flag = 0;
            dfs(1,1,0);
            if(flag == 1)
                printf("YES\n");
            else
                printf("NO\n");
            /*for(int i = 0; i < 10; i++)
                printf("%d",b[i]);
            //printf("\n\n\n\n");
            /*for(int i = 0; i < 10; i++)
                printf("%d",c[i]);
            printf("\n");*/

        }
    }
    return 0;
}

C++: /*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\2????????????????????????????????\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\??§???????????¶???????´????????????\??°?????\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[10], b[2][10];
int len[2];
bool ans;


void dfs(int step) {
  if (ans) return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] == 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  len[0] = len[1] = 0;
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
/*
int dfs(int w,int h,int noww,int nowh,int n,int b){
	++n;
	if(noww>w || nowh>h) return 0;
	if(noww==w && nowh==h) return 1;
	int ret=0;
	for(int i=0; i<2; ++i){
		if(n>=2){
			n=0;
			if(i==0){
				b=1;
				ret+=dfs(w,h,++noww,nowh,n,b);
			} else if(i==1){
				b=2;
				ret+=dfs(w,h,noww,++nowh,n,b);
			}
		} else{
			if(b==1)ret+=dfs(w,h,++noww,nowh,n,b);
			if(b==2)ret+=dfs(w,h,noww,++nowh,n,b);
		}
	}
	return ret;
}

int main()u{
	int w,h;
	cin >> w >> h;
	cout << dfs(w,h,1,1,2,0) << endl;
	return 0;
}
*/
int calc(vector<int> balls,int i,int cas1,int cas2,int a,int sum);

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; ++i){
		vector<int> balls(10);
		for(int i=0 ;i<10; ++i){
			cin >> balls[i];
		}
		int sum=0;
		if(calc(balls,0,0,0,0,sum)>0){
			cout << "YES" << endl;
		} else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

int calc(vector<int> balls,int i,int cas1,int cas2,int a,int sum){
	if(i==10) {
		//cout << cas1 << " " << cas2 << " " << a << " " << balls[i-1] << endl;
		return 1;
	}
	if(a==0&&balls[i]<cas1) return 0;
	if(a==1&&balls[i]<cas2) return 0;
	if(a==0)cas1=balls[i];
	if(a==1)cas2=balls[i];
	sum += calc(balls,i+1,cas1,cas2,0,sum);
	sum += calc(balls,i+1,cas1,cas2,1,sum);

	return sum;
}

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

#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)

int main(){
    int n;
    cin >> n;
    REP(i,n){
        int a, p1 = 0, p2 = 0;
        bool flag = true;
        REP(j,10){
            cin >> a;
            if(p1 >= p2 && p1 < a){
                p1 = a;
            } else if(p2 < a){
                p2 = a;
            } else {
                flag = false; break;
            }
        }
        cout << (flag?"YES":"NO") << endl;
    }
    return 0;
}

C++: #include <iostream>
#define CAPACITY 9
using namespace std;
int b, c;

bool dfs(int pos, int ary[], bool flag) {
    if(pos < 0) {
        return(false);
    }
    
    flag = dfs(pos - 1, ary, flag);
    
    if(pos == CAPACITY) {
        flag = true;
    }
    if(ary[pos] > b) {
        b = ary[pos];
    } else if(ary[pos] > c) {
        c = ary[pos];
    } else {
        return(false);
    }
    cout << "B = " << b << "C = " << c << endl;
    
    return(flag);
}

int main(void) {
    int num;
    
    cin >> num;
    int ary[10];
    
    for(int r = 0; r < num; r++) {
        for(int c = 0; c < 10; c++) {
            cin >> ary[c];
        }
        b = ary[0];
        c = INT_MIN;
        if(dfs(CAPACITY, ary, true)) {
            cout << "YES";
        } else {
            cout << "NO";
        }
        cout << endl;
    }
    
    return(0);
}

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

int main(void){
  int N,temp,flag;
  vector<int> A,B(1,0),C(1,0);
  cin >> N;
  for(int i=0; i<N; ++i){
    while(!A.empty()){
      for(int j=0; j<10; ++j){
	cin >> temp;
	A.push_back(temp);
      }
      temp = A.front();
      if(temp>=*B.end()) B.push_back(temp);
      if(temp>=*C.end()) C.push_back(temp);
      else{
	cout << "NO" << endl;
	flag = 1;
	break;
      }
      A.pop_back();
    }
    if(flag!=1)
      cout << "YES" << endl;
    flag=0;
  }
}

C++: #include<iostream>
#include<vector>
using namespace std;
bool a[15]; 
int d[15];
vector<int> b,c;
int judge; 
void dfs(int n){
	if(n==10){
		for(int i=0;i<10;i++){
			if(a[i]==false){//进c 
				c.push_back(d[i]);
			}
			else{
				b.push_back(d[i]);
			}
		}
		int ok=1;
		for(int j=0;j<b.size()-1;j++){
			if(b[j]>b[j+1]){
				ok=0;
				break;
			}
		}
		for(int j=0;j<c.size()-1;j++){
			if(c[j]>c[j+1]){
				ok=0;
				break;
			}
		}
		if(ok)judge=1;
	}
	else{
		a[n]=true;
		dfs(n+1);
		a[n]=false;
		dfs(n+1);
	}
}
int main(){
	int n;
	cin>>n;
	while(n--){
		b.clear();c.clear(); 
		judge=0;
		for(int i=0;i<10;i++){
			cin>>d[i];
		}
		dfs(0);
		if(judge){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}