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 <vector>

#define bottom(v) v[v.size()-1]

using namespace std;

int main() {
  int n, t;
  vector<int> v1, v2;
  cin>>n;
  
  while(n--) {
    bool isOk = true;
    for(int i = 0; i < 10; i++) {
      cin>>t;
      if(v1.empty() || bottom(v1)<t) v1.push_back(t);
      else if(v2.empty() || bottom(v2)<t) v2.push_back(t);
      else isOk = false;
    }
    cout << (isOk ? "YES" : "NO") << endl;
    v1.clear(); v2.clear();
  }
  return 0;
}

C++: //-*-coding:utf-8-*-
//----------------------------------------------------------
// module: main
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033
//----------------------------------------------------------
#include <algorithm>
#include <vector>
#include <deque>
#include <map>

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXL = 10;

int numbers[MAXL];

bool can_solve(int i, int a, int b){
    int v = numbers[i];
    if (i >= MAXL) return true;

    if (v > a && can_solve(i+1, v, b)) return true;
    if (v > b && can_solve(i+1, a, v)) return true;
    return false;
}

bool solve(){
    return can_solve(0, -1, -1);

    int a = -1;
    int b = -1;
    for (int i = 0; i < 10; ++i)
        {
            if (a > b && b > 0) {
                if (numbers[i] > a) { a = numbers[i]; }
                else if (numbers[i] > b) { b = numbers[i]; }
                else return false;
            }
            else if (b > a && a > 0){
                if (numbers[i] > b) { b = numbers[i]; }
                else if (numbers[i] > a) { a = numbers[i]; }
                else return false;
            }
                
            if(a < 0){a = numbers[i]; continue; };
            if(b < 0){b = numbers[i]; continue; };
        }
    return true;
};

int main(int argc, char *argv[])
{
    int c;
    scanf("%d", &c);
    for (int i = 0; i < c; ++i)
        {
            scanf("%d %d %d %d %d %d %d %d %d %d", &numbers[0], &numbers[1], &numbers[2], &numbers[3], &numbers[4], &numbers[5], &numbers[6], &numbers[7], &numbers[8], &numbers[9]);
            bool result = solve();
            if ( solve() ){ printf("YES\n"); }
            else { printf("NO\n"); }
        }
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){

  int n,i;
  cin >> n;
  for(i=0;i<n;i++){
    int j;
    int tmp;
    int han=0;
    vector<int>in1;
    vector<int>in2;
    for(j=0;j<5;j++){
      cin >> tmp;
      in1.push_back(tmp);
      cin >> tmp;
      in2.push_back(tmp);
    }
    for(j=1;j<5;j++){
      if(in1[j-1]>in1[j])
	han=1;
      if(in2[j-1]>in2[j])
	han=1;
    }

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


}

C++: //
// Create by 神舟 on 2015-02-20
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>
using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long
#define inf 0x3f3f3f3f
const int maxn=1e1+5;
const int MOD=5e5+5;
int n;
int dp[maxn];
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	scanf("%d",&n);
	while(n--){
        CLR(dp);
        int num;
        int maxlen=0;
        dp[maxlen]=inf;
        int flag=1;
        for(int i=1;i<11;i++){
            scanf("%d",&num);
            if(maxlen>2) flag=0;
            if(num<=dp[maxlen])
                dp[++maxlen]=num;
            else{
                int l=1,r=maxlen;
                while(l<=r){
                    int mid=l+(r-l)/2;
                    if(dp[mid]>num) l=mid+1;
                    else r=mid-1;
                }
                dp[l-1]=num;
            }
        }
        if(flag) printf("YES\n");
        else printf("NO\n");
	}

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
using namespace std;
const int manx = 500;
stack <int> a;
stack <int> b;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int input;
        int flag = true;
        scanf("%d",&input);
        a.push(input);
        b.push(0);
        for(int i = 1 ; i < 10 ; i++)
        {
            scanf("%d",&input);
            int ai = input - a.top();
            int bi = input - b.top();
            if(ai <= 0 && bi <= 0)
            {
                flag = false;
                printf("NO\n");
                break;
            }
            if(ai > 0 && bi <= 0)
                a.push(input);
            if(bi > 0 && ai <= 0)
                b.push(input);
            if(ai > 0 && bi > 0)
            {
                if(ai > bi )
                    b.push(input);
                if(ai <= bi)
                    a.push(input);
            }
        }
        if(flag == false)
            continue;
        else
            printf("YES\n");
        while( !a.empty() )
            a.pop();
        while( !b.empty() )
            b.pop();
    }
    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define scai(x) scanf("%d", &x)
#define scac(x) scanf("%c", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define pri(x) printf("%d", x)
#define prc(x) printf("%c", x)
#define pri2(x,y) printf("%d %d", x, y)
#define prif(x) printf("%lf", x)
#define prif2(x, y) printf("%lf %lf", x, y)
#define mset(x, y) memset(x, y, sizeof(x))
#define fori(i, x, y) for(int i = x; i < y; i++)
#define pii pair<int, int>
#define pic pair<int, char>
#define pdd pair<double, double>
typedef long long ll;
const int N = 13;
int a[N];
int zuo[N];
int you[N];
int lc, rc;



bool solve()
{
    for(int i = 0; i < 1024; i++)
    {
        mset(zuo, 0);
        mset(you, 0);
        lc = rc = 0;
        int cnt;
        int j;
        for(j = i, cnt = 0; cnt < 10; cnt++, j >>= 1)
        {
            if(j & 1) zuo[lc++] = a[cnt];
            else you[rc++] = a[cnt];
        }
        bool flag = true;
        for(j = 1; j < lc; j++)
        {
            if(zuo[j] < zuo[j - 1]) {
                flag = 0;
                break;
            }
        }

        if(flag){
            for(j = 1; j < rc; j++){
                if(you[j] < you[j - 1]) {
                    flag = 0;
                    break;
                }
            }
        }

        if(flag) return true;
    }
    return false;
}


int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        for(int i = 0; i < 10; i++)
        {
            scai(a[i]);
        }
        puts(solve()? "YES" : "NO");
    }
    return 0;
}