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 <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int MAX_N = 10;
int a[MAX_N];

bool dfs(int idx, int end1, int end2) {
    if (idx+1 == MAX_N) return true;
    if (a[idx] < end1 && a[idx] < end2) return false;
    if (a[idx] > end1 && a[idx] > end2) return dfs(idx+1, a[idx], end2) || dfs(idx+1, end1, a[idx]);
    if (a[idx] > end1) return dfs(idx+1, a[idx], end2);
    if (a[idx] > end2) return dfs(idx+1, end1, a[idx]);
    return false;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        for (int i = 0; i < MAX_N; i++)
            cin >> a[i];
        bool flag = dfs(0, 0, 0);
        if (flag) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <map> 
#include <iostream>
#include <cctype>
#include <utility> // 包含pair 
using namespace std;
typedef long long LL;
const int MAXN = 10 + 10;
int a[MAXN];
stack<int> s1, s2; // 建立两个栈，用于模拟小球进栈的过程
// 当前第idx个元素 
bool dfs(int idx) {
	if (idx == 10) {
		return true; // 所有元素都遍历完了(思考这里是true还是false) 应该是true 
	}
	if (s1.empty() || a[idx] > s1.top()) {
		s1.push(a[idx]);
		if (dfs(idx + 1)) {
			s1.pop(); // 回溯
			return true; 
		}
	}
	if (s2.empty() || a[idx] > s2.top()) {
		s2.push(a[idx]);
		if (dfs(idx + 1)) {
			s2.pop();
			return true;
		}
	}
	return false; // 都不满足则返回假 
}

int main() {
	// ios::sync_with_stdio(false);
	int T;
	scanf("%d", &T);
	while (T--) {
		// while (!s1.empty()) s1.pop();
		// while (!s2.empty()) s2.pop(); 如果是回溯法的话，其实不需要这两行 
		for (int i = 0; i < 10; i++) {
			scanf("%d", &a[i]);
		}
		if (dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	
    return 0;
}

C++: #include <iostream>

using namespace std;
const int kBalln = 10;
int main(){
  int n;
  int ball;
  int b, c;
  bool ans;
  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      b = 0; c = 0;ans = true;
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball;
          if (b < ball)
            {
              b = ball;
            }
          else if (c < ball)
            {
              c = ball;
            }
          else
            {
              // cout << "NO" << endl;
              break;
            }
        }
      cout << (ans ? "YES" : "NO") << endl;
    }
  return 0;
}

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

int boal[10];

bool dfs(int b,int c, int time)
{
	if(time >= 10)
		return true;
	
	if(boal[time] > b && dfs(boal[time], c, time + 1))
		return true;
	
	if(boal[time] > c && dfs(b, boal[time], time + 1))
		return true;
	
	return false;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	while(n > 0){
		for(int i = 0; i != 10; ++i)
			cin >> boal[i];
		
		if(dfs(0, 0, 0))
			cout << "YES";
		else
			cout << "NO";
		cout << endl;
		
		n--;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool DFS(int t_b,int t_c,int th,int* balls){
  if(th==10)return true;
  if(t_b<balls[th]&&t_c<balls[th])
      if(t_b>t_c)return DFS(balls[th],t_c,th+1,balls);
      else return DFS(t_b,balls[th],th+1,balls);
  else if(t_b<balls[th])return DFS(balls[th],t_c,th+1,balls);
  else if(t_c<balls[th])return DFS(t_b,balls[th],th+1,balls);
  else return false;
}
int main(){
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
    int balls[10];
    for(int i=0;i<10;i++)cin>>balls[i];
    int t_b=0,t_c=0;int drop_balls=0;
    if(DFS(0,0,0,balls))cout<<"YES";
    else cout<<"NO";
    cout<<endl;
  }
}

C++: #include <iostream>
#include <queue>
#include <stack>
using namespace std;
stack<int> stal, star;
queue<int> que;
bool dfs();

int main() {
    int n;

    while (cin >> n) {
        int num;
        while (n--) {
            while (!que.empty()) que.pop();
            for (int i = 0; i < 10; i++) {
                cin >> num;
                que.push(num);
            }
            while (!stal.empty()) stal.pop();
            while (!star.empty()) star.pop();
            cout << (dfs() ? "YES" : "NO") << endl;
        }
    }

    return 0;
}

bool dfs() {
    bool flag = true, enter = false;
    if (stal.empty() || stal.top() < que.front()) {
        stal.push(que.front());
        que.pop();
        flag = dfs();
        enter = true;
    }
    if (!flag && !enter) { que.push(stal.top()); stal.pop(); }
    if ((star.empty() || star.top() < que.front()) && (!flag || !enter)) {
        star.push(que.front());
        que.pop();
        dfs();
    }
    if (que.empty()) return true;
    else return false;
}

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

int D, A[10];
const int MAX_DATA = 100000;
bool owata[MAX_DATA];

bool dfs(int n,int a,int b)
{
	if(n==10)
	{
		return true;
	}

	if(A[n]>a){
	if(dfs(n+1,A[n],b))
	{
		return true;
	}
	}

	if(A[n]>b){
	if(dfs(n+1,a,A[n]))
	{
		return true;
	}
	}

	return false;

}

int main(){
	cin>>D;
	for(int i=1;i<=D;i++){
		for(int j=0;j<10;j++){
			cin>>A[j];
		}

		owata[i] = dfs(0, 0, 0);
	}
	for(int i=1;i<=D;i++)
	{
		cout << (owata[i] ? "YES":"NO") << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int a=0,b=0;
  int c;
  cin>>c;
  for(int i=0;i<c;i++){
    a=0;
    b=0;
    for(int i=0;i<10;i++){
      int t;
      cin>>t;
      if(t<a&&t<b){
	cout<<"NO"<<endl;
	break;
      }
      if(a<t)a=t;
      else b=t;
      if(i==9)cout<<"YES"<<endl;
    }
  }
  return 0;
}

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

int l[11],r[11],n[11];
int N;
int final;

void dfs(int i,int ll,int rr)
{
	if(i==11)
	{
		final=1;
		return;
	}
	if(n[i]>l[ll-1])
	{
		l[ll]=n[i];
		dfs(i+1,ll+1,rr);
	}
	if(n[i]>r[rr-1])
	{
		r[rr]=n[i];
		dfs(i+1,ll,rr+1);
	}
}

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		for(int j=1;j<=10;j++)
		{
			cin>>n[j];
		}
		final=0;
		dfs(1,1,1);//从1开始比0更好 
		if(final)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	
	return 0;
}

C++: /*
P135
POJ 2718 Smallest Difference
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int a[10];
bool read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
}


//
//vector<int> L_bucket;
//vector<int> R_bucket;
//
//bool dfs2(int d){
//    if(d == 10) return true;
//    bool flag = false;
//    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
//        L_bucket.push_back(a[d]);
//        flag = dfs2(d+1);
//        L_bucket.pop_back();
//    }
//    if(flag) return true;
//    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
//        R_bucket.push_back((a[d]));
//        flag = dfs2(d+1);
//        R_bucket.pop_back();
//    }
//    if(flag) return true;
//    return false;
//}
//
//void solve2()
//{
//    if(dfs2(0)) printf("YES\n");
//    else printf("NO\n");
//}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve();
    }
}