#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
// typedef unsigned long long ulong;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned char uchar;

#define MAX_INT 0x7fffffff
#define MIN_INT 0x80000000
#define MAX_UINT 0xffffffff
#define EPS (1e-12)
template<class T> inline T SQR(T x) { return x * x; }
template<class T> inline string TOSTR(const T & x) { stringstream ss; ss << x; return ss.str(); }

#define FORN(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define FOR(i,s,n) for(int (i)=s;(i)<(int)(n);(i)++)
#define ITER(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SWAP(a, b, tmp) {__typeof(a) tmp = a; a = b; b = tmp;}
#ifndef ONLINE_JUDGE
    #define EPR(args...) fprintf (stderr, args)
#else
    #define EPR(args...) 1
#endif

#if 1 // disable print
    #undef EPR
    #define EPR(args...) 1
#endif

#define SZ(x) ((int)(x).size())
#define FORV(i,v) FORN(i,SZ(v))
#define MAX(a,b) ((a > b) ? a : b)
#define MIN(a,b) ((a < b) ? a : b)

#define PR(x) cout << x << endl
#define PRF(x) cout << setprecision(10) << x << endl
#define POW2(x) (1ll<<(x))

int gcd(int a,int b){return a?gcd(b%a,a):b;}
LL gcd(LL a,LL b){return a?gcd(b%a,a):b;}
LL powmod(LL a,LL p,LL m){LL r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;}

const int MOD = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932384626433832795l;

double arr[2][50050];
double *prob;
double *prob2;
double ANSWER = 0;

#define get(i) ((i >= min_T && i <= max_T) ? prob[i] : 0)
// #define get(i) prob[i]

int main() {
    // bzero(arr, sizeof(arr));
    int N, T;
    double pi;
    int ti;

    prob = arr[0];
    prob2 = arr[1];
    cin >> N >> T;
    prob[T] = 1.0;

    int min_T = T;
    int max_T = T;
    FORN(asd_nsong, N) {
        int nsong = asd_nsong + 1;
        cin >> pi >> ti;
        pi /= 100.0;
        int min_T2 = MAX_INT;
        int max_T2 = -1;

        double p = pi;
        double q = 1 - p;
        double qpow = pow(q, ti - 2);
        double qpow_q = qpow * q;
        double qpow_p = qpow * p;

        if (p >= 1.0 - EPS) {
            qpow = 0;
            qpow_q = 0;
            qpow_p = 0;
        }

        int ptr1 = max_T + 1;
        int ptr2 = max_T;
        double acc = 0, val = 0;
        int T2 = max_T;
        EPR("nsong %d(len=%d): (%d %d) p %lf q %lf qpow %lf\n", nsong, ti, min_T, max_T, p, q, qpow);

        while (1) {
            T2--;
            if (T2 + ti < min_T)
                break;

            ptr1--;
            if (ptr2 - ptr1 >= ti - 1) {
                acc -= get(ptr2) * qpow_p;
                ptr2--;
                if (ptr2 < -1)
                    break;
            }
            acc = acc * q;
            if (ptr1 >= 0) {
                acc += prob[ptr1] * p;
            }
            else {
                if (acc < 1e-25 && qpow_q * N < 1e-25)
                    break;
            }
            val = acc;

            if (T2 + ti <= max_T)
                val += prob[T2 + ti] * qpow_q;

            // printf("  acc %lf val %lf: %d -> %d?\n", acc, val, min_T2, T2);
            if (val > 0) {
                min_T2 = MIN(min_T2, T2);
            }

            if (T2 >= 0) {
                prob2[T2] = val;
            }
            else {
                // EPR("+%lf\n", val);
                EPR("%lf +%lf = ", ANSWER, val * (nsong - 1));
                ANSWER += val * (nsong - 1);
                EPR("%lf\n", ANSWER);
            }
            // cnt++;
        }
        max_T2 = max_T - 1;
        // printf("\n");

        // prob = arr[nsong];
        // prob2 = arr[nsong + 1];
        SWAP(prob, prob2, tmp);
        min_T = MAX(0, min_T2);
        max_T = max_T2;
        EPR("nsong end %d: (%d %d) (CNT: %l64u)\n", nsong, min_T, max_T);
        if (max_T < 0) {
            break;
        }
    }
    FOR(i, MAX(0, min_T), max_T + 1) {
        EPR("%lf +%lf = ", ANSWER, prob[i] * N);
        ANSWER += prob[i] * N;
        EPR("%lf\n", ANSWER);
    };

    PRF(ANSWER);
    return 0;
}


#include <bits/stdc++.h>

#define N 5050
double dp[N][N], t[N], p[N];
double calc(double x, int bit) {
	double ret = 1.;
	while(bit) {
		if(bit & 1)
			ret = ret * x;
		x = x * x;
		bit >>= 1;
	}
	return ret;
}
int main() {
	int n, T;
	scanf("%d%d", &n, &T);
	for(int i = 1; i <= n; i ++) {
		scanf("%lf%lf", p + i, t + i);
		p[i] /= 100.;
	}
	dp[0][0] = 1.;
	double ans = 0;
	for(int i = 1; i <= n; i ++) {
		int k = 0;
		double sum = dp[i - 1][0], over = 0, tmp = 0;
		for(int j = 1; j <= T; j ++) {
			if(k + t[i] == j) {
				over = calc(1 - p[i], t[i] - 1) * dp[i - 1][k];
				sum -= calc(1 - p[i], t[i] - 1) * dp[i - 1][k];
				k ++;
			}
	//		if(j >= t[i] && i != 1)
	//			tmp += dp[i - 1][int(j - t[i])];
			dp[i][j] = sum * p[i];
			dp[i][j] += over;
			sum *= (1 - p[i]);
			sum += dp[i - 1][j];
		}
	//	printf("i: %d %lf\n", i, dp[i][T]);
		ans += dp[i][T] * i;
		ans += (sum - dp[i - 1][T]) * (i - 1);
	}
	printf("%.10lf\n", ans);
	return 0;
}


#include <bits/stdc++.h>

#define N 5050
double dp[N][N], t[N], p[N];
double calc(double x, int bit) {
	double ret = 1., t = x;
	while(bit) {
		if(bit & 1)
			ret = ret * x;
		x = x * x;
		bit >>= 1;
	}
	return ret;
}
int main() {
	int n, T;
	scanf("%d%d", &n, &T);
	for(int i = 1; i <= n; i ++) {
		scanf("%lf%lf", p + i, t + i);
		p[i] /= 100.;
	}
	dp[0][0] = 1.;
	double ans = 0;
	for(int i = 1; i <= n; i ++) {
		int k = 0;
		double sum = dp[i - 1][0], over = 0, tmp = 0;
		for(int j = 1; j <= T; j ++) {
			if(k + t[i] == j) {
				over = calc(1 - p[i], t[i] - 1) * dp[i - 1][k];
				sum -= over;
				k ++;
			}
	//		if(j >= t[i] && i != 1)
	//			tmp += dp[i - 1][int(j - t[i])];
			dp[i][j] = sum * p[i];
			dp[i][j] += over;
			sum *= (1 - p[i]);
			sum += dp[i - 1][j];
		}
	//	printf("i: %d %lf\n", i, dp[i][T]);
		ans += dp[i][T] * i;
		ans += (sum - dp[i - 1][T]) * (i - 1);
	}
	for(int i = 0; i < T; i ++)
		ans += dp[n][i] * n;
	printf("%.10lf\n", ans);
	return 0;
}


#include <bits/stdc++.h>

#define N 5050
double dp[N][N], t[N], p[N];
std::map<double, double> hash;
double calc(double x, int bit) {
	if(hash.count(x))
		return hash[x];
	double ret = 1., t = x;
	while(bit) {
		if(bit & 1)
			ret = ret * x;
		x = x * x;
		bit >>= 1;
	}
	hash[t] = ret;
	return ret;
}
int main() {
	int n, T;
	scanf("%d%d", &n, &T);
	for(int i = 1; i <= n; i ++) {
		scanf("%lf%lf", p + i, t + i);
		p[i] /= 100.;
	}
	dp[0][0] = 1.;
	double ans = 0;
	for(int i = 1; i <= n; i ++) {
		int k = 0;
		double sum = dp[i - 1][0], over = 0, tmp = 0;
		for(int j = 1; j <= T; j ++) {
			if(k + t[i] == j) {
				over = calc(1 - p[i], t[i] - 1) * dp[i - 1][k];
				sum -= over;
				k ++;
			}
	//		if(j >= t[i] && i != 1)
	//			tmp += dp[i - 1][int(j - t[i])];
			dp[i][j] = sum * p[i];
			dp[i][j] += over;
			sum *= (1 - p[i]);
			sum += dp[i - 1][j];
		}
	//	printf("i: %d %lf\n", i, dp[i][T]);
		ans += dp[i][T] * i;
		ans += (sum - dp[i - 1][T]) * (i - 1);
	}
	for(int i = 0; i < T; i ++)
		ans += dp[n][i] * n;
	printf("%.10lf\n", ans);
	return 0;
}


#include <bits/stdc++.h>

#define N 5050
double dp[N][N], t[N], p[N];
std::map<double, double> hash;
double calc(double x, int bit) {
	if(hash.count(x))
		return hash[x];
	double ret = 1.;
	while(bit) {
		if(bit & 1)
			ret = ret * x;
		x = x * x;
		bit >>= 1;
	}
	return ret;
}
int main() {
	int n, T;
	scanf("%d%d", &n, &T);
	for(int i = 1; i <= n; i ++) {
		scanf("%lf%lf", p + i, t + i);
		p[i] /= 100.;
	}
	dp[0][0] = 1.;
	double ans = 0;
	for(int i = 1; i <= n; i ++) {
		int k = 0;
		double sum = dp[i - 1][0], over = 0, tmp = 0;
		for(int j = 1; j <= T; j ++) {
			if(k + t[i] == j) {
				over += calc(1 - p[i], t[i] - 1) * dp[i - 1][k];
				sum -= calc(1 - p[i], t[i] - 1) * dp[i - 1][k];
				k ++;
			}
	//		if(j >= t[i] && i != 1)
	//			tmp += dp[i - 1][int(j - t[i])];
			dp[i][j] = sum * p[i];
			dp[i][j] += over;
			sum *= (1 - p[i]);
			sum += dp[i - 1][j];
		}
	//	printf("i: %d %lf\n", i, dp[i][T]);
		ans += dp[i][T] * i;
		ans += (sum - dp[i - 1][T]) * (i - 1);
	}
	printf("%.10lf\n", ans);
	return 0;
}


#include <bits/stdc++.h>

#define N 5050
double dp[N][N], t[N], p[N];
double calc(double x, int bit) {
	double ret = 1., t = x;
	while(bit) {
		if(bit & 1)
			ret = ret * x;
		x = x * x;
		bit >>= 1;
	}
	return ret;
}
int main() {
	int n, T;
	scanf("%d%d", &n, &T);
	for(int i = 1; i <= n; i ++) {
		scanf("%lf%lf", p + i, t + i);
		p[i] /= 100.;
	}
	dp[0][0] = 1.;
	double ans = 0;
	for(int i = 1; i <= n; i ++) {
		int k = 0;
		double sum = dp[i - 1][0], over = 0, tmp = 0;
		double powPi = calc(1 - p[i], t[i] - 1);
		for(int j = 1; j <= T; j ++) {
			if(k + t[i] == j) {
				over = powPi * dp[i - 1][k];
				sum -= over;
				k ++;
			}
	//		if(j >= t[i] && i != 1)
	//			tmp += dp[i - 1][int(j - t[i])];
			dp[i][j] = sum * p[i];
			dp[i][j] += over;
			sum *= (1 - p[i]);
			sum += dp[i - 1][j];
		}
	//	printf("i: %d %lf\n", i, dp[i][T]);
		ans += dp[i][T] * i;
		ans += (sum - dp[i - 1][T]) * (i - 1);
	}
	for(int i = 0; i < T; i ++)
		ans += dp[n][i] * n;
	printf("%.10lf\n", ans);
	return 0;
}


import java.util.ArrayList;
import java.util.Scanner;

public class try2 {

	public static boolean issorted(ArrayList<Integer> list) {
		for (int i = 0; i < list.size()-1; i++) {
			if(list.get(i)>list.get(i+1)) {
				return false;
			}
		}
		return true;
	}

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int loops=sc.nextInt();
		for (int i = 0; i < loops; i++) {
			int length=sc.nextInt();
			ArrayList<Integer> number=new ArrayList<Integer>();
			for (int j = 0; j < length; j++) {
				number.add(j+1);
			}
			String output="YES";
			ArrayList<Integer> list=new ArrayList<Integer>();

			for (int j = 0; j < length; j++) {
				int element=sc.nextInt();
				if(j==0 && element==length) {
					output="NO";
				}
				if(j==length-1 && element==1) {
					output="NO";
				}
				if(list.isEmpty()) {
					list.add(element);
					number.remove(element-1);
				}else {
					int last=list.get(list.size()-1);
					if(element>last) {
						if(number.get(number.size()-1)>element) {
							list.set(list.size()-1, element);
							number.remove(element-1);
						}
					}else {
						list.add(element);
						number.remove(element-1);
					}
				}

			}
			if(output.equals("NO")){
			System.out.println(output);
			}else{
				System.out.println("YES");
			}
		}
	}

}


import java.util.Scanner;

public class try2 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int loops=sc.nextInt();
		for (int i = 0; i < loops; i++) {
			int length=sc.nextInt();
			String output="YES";

			for (int j = 0; j < length; j++) {
				int element=sc.nextInt();
				if(j==0 && element==length) {
					output="NO";
				}
				if(j==length-1 && element==1) {
					output="NO";
				}

			}
			System.out.println(output);
		}
	}

}


import java.io.*;
import java.util.*;
public class rugrwr {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
    while(t-- > 0)
        {
            int n = sc.nextInt();
            int [] ans = new int[n];
            for(int i=0;i<n;i++)
                ans[i] = sc.nextIntArray(n);
            if(ans[0]>ans[n-1])
                System.out.println("NO");
            else
                System.ou.println("YES");
        }

    }

}


import java.io.*;
import java.util.*;
public class rugrwr {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
    while(t-- > 0)
        {
            int n = sc.nextInt();
            int [] ans = new int[n];
            for(int i=0;i<n;i++)
                ans[i] = sc.nextInt();
            if(ans[0]>ans[n-1])
                System.out.println("NO");
            else
                System.out.println("YES");
        }

    }

}


import java.util.*;
public class rugrwr {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
    while(test-- > 0)
        {
            int n = sc.nextInt();
            int [] ans = new int[n];
            for(int i=0;i<n;i++)
                ans[i] = sc.nextIntArray(n);
            if(ans[0]>ans[n-1)
                System.out.println("NO");
            else
                System.ou.println("YES");
        }
        pw.close();
    }

}


import java.util.*;
public class rugrwr {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
    while(test-- > 0)
        {
            int n = sc.nextInt();
            int [] ans = new int[n];
            for(int i=0;i<n;i++)
                ans[i] = sc.nextIntArray(n);
            if(ans[0]>ans[n-1)
                System.out.println("NO");
            else
                System.ou.println("YES");
        }

    }

}


import java.io.*;
import java.util.*;
public class rugrwr {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
    while(t-- > 0)
        {
            int n = sc.nextInt();
            int [] ans = new int[n];
            for(int i=0;i<n;i++)
                ans[i] = sc.nextIntArray(n);
            if(ans[0]>ans[n-1])
                System.out.println("NO");
            else
                System.out.println("YES");
        }

    }

}


import java.util.*;
public class rugrwr {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
    while(test-- > 0)
        {
            int n = sc.nextInt();
            int [] ans = new int[n];
            for(int i=0;i<n;i++)
                ans[i] = sc.nextIntArray(n);
            if(ans[0]>ans[n-1])
                System.out.println("NO");
            else
                System.ou.println("YES");
        }
        pw.close();
    }

}


function solve() {
   var n = Number(read());
   var a = read().split(' ').map(Number);
   var b = a.slice();
   for (var i = n - 2; i >= 0; i--) {
      b[i] = Math.max(b[i], b[i + 1]);
   }
   var cur = -1;
   var prev = 0;
   for (var i = 0; i < n; i++) {
      if (cur < prev && a[i] > prev) {
         cur = a[i];
      }
      if (a[i] === b[i]) {
         write(cur);
         if (cur < prev) {
            write('NO');
            return;
         }
         prev = cur;
         cur = -1;
      }
   }
   write('YES');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


function solve() {
   var n = Number(read());
   var a = read().split(' ');
   var b = [0];
   for (var i = 0; i < n; i++) {
      a[i] = Number(a[i]);
      b.push(0);
   }
   var prev = 0;
   var cur = n + 1;
   var wait = n;
   var found = false;
   var nextWaitIndex = n;
   for (var i = 0; i < n; i++) {
      b[a[i]] = 1;
      if (a[i] > prev && !found) {
         cur = a[i];
         found = true;
      }
      if (a[i] === wait) {
         if (!found) {
            write('NO');
            return;
         }
         prev = cur;
         found = false;
         while(b[nextWaitIndex]) {
            nextWaitIndex--;
         }
         wait = nextWaitIndex;
      }
   }
   write('YES');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


function solve() {
   var n = Number(read());
   var a = read().split(' ');
   var b = [0];
   for (var i = 0; i < n; i++) {
      a[i] = Number(a[i]);
      b.push(0);
   }
   var prev = 0;
   var cur = n + 1;
   var wait = n;
   var found = false;
   var nextWaitIndex = n;
   for (var i = 0; i < n; i++) {
      b[a[i]] = 1;
      if (!found) {
         cur = a[i];
         found = true;
      } else if (cur < prev && a[i] > cur) {
         cur = a[i];
      }
      if (a[i] === wait) {
         if (cur < prev) {
            write('NO');
            return;
         }
         prev = cur;
         found = false;
         while(b[nextWaitIndex]) {
            nextWaitIndex--;
         }
         wait = nextWaitIndex;
      }
   }
   write('YES');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


var N = 300000;
var B = [];
for (var I = 0; I < N; I++) {
   B.push(I + 1);
}

function solve() {
   var n = Number(read());
   var a = read().split(' ').map(Number);
   var prev = 0;
   var cur = n + 1;
   var wait = n;
   var nextWaitIndex = n - 2;
   for (var i = 0; i < n; i++) {
      if (a[i] === B[nextWaitIndex]) {
         nextWaitIndex--;
      }
      if (a[i] > prev && a[i] < cur) {
         cur = a[i];
      }
      if (a[i] === wait) {
         if (cur === n + 1) {
            write('NO');
            return;
         }
         prev = cur;
         cur = n + 1;
         wait = B[nextWaitIndex--];
      }
   }
   write('YES');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


function solve() {
   var n = Number(read());
   var a = read().split(' ').map(Number);
   write(a[0] < a[n - 1] ? 'YES' : 'NO');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


function solve() {
   var n = Number(read());
   var a = read().split(' ');
   var b = [0];
   for (var i = 0; i < n; i++) {
      a[i] = Number(a[i]);
      b.push(0);
   }
   var prev = 0;
   var cur = n + 1;
   var wait = n;
   var nextWaitIndex = n - 1;
   for (var i = 0; i < n; i++) {
      b[a[i]] = 1;
      if (a[i] > prev && a[i] < cur) {
         cur = a[i];
      }
      if (a[i] === wait) {
         if (cur === n + 1) {
            write('NO');
            return;
         }
         prev = cur;
         cur = n + 1;
         while(b[nextWaitIndex]) {
            nextWaitIndex--;
         }
         wait = nextWaitIndex--;
      }
   }
   write('YES');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


function solve() {
   var n = Number(read());
   var a = read().split(' ').map(Number);
   var b = a.slice();
   for (var i = n - 2; i >= 0; i--) {
      b[i] = Math.max(b[i], b[i + 1]);
   }
   var cur = -1;
   var prev = 0;
   for (var i = 0; i < n; i++) {
      if (cur < prev && a[i] > cur) {
         cur = a[i];
      }
      if (a[i] === b[i]) {
         if (cur < prev) {
            write('NO');
            return;
         }
         prev = cur;
         cur = -1;
      }
   }
   write('YES');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


function solve() {
   var n = Number(read());
   var a = read().split(' ');
   var b = [0];
   for (var i = 0; i < n; i++) {
      a[i] = Number(a[i]);
      b.push(0);
   }
   var prev = 0;
   var cur = n + 1;
   var wait = n;
   var found = false;
   var nextWaitIndex = n;
   for (var i = 0; i < n; i++) {
      b[a[i]] = 1;
      if (!found) {
         cur = a[i];
         found = true;
      } else if (cur < prev && cur === a[i - 1] && a[i] > cur) {
         cur = a[i];
      }
      if (a[i] === wait) {
         if (cur < prev) {
            write('NO');
            return;
         }
         prev = cur;
         found = false;
         while(b[nextWaitIndex]) {
            nextWaitIndex--;
         }
         wait = nextWaitIndex;
      }
   }
   write('YES');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


function solve() {
   var n = Number(read());
   var a = read().split(' ').map(Number);
   var cur = a[0];
   var found = true;
   for (var i = 1; i < n; i++) {
      if (a[i - 1] < a[i]) {
         if (!found && a[i] > cur) {
            cur = a[i];
            found = true;
         }
      } else {
         if (!found) {
            write('NO');
            return;
         }
         found = false;
      }
   }
   write(found ? 'YES' : 'NO');
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


#include <bits/stdc++.h>

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;
int main()
{
    int t;  cin >> t;
    while (t--)
    {
        int n;  cin >> n;
        vector <int> v(n + 1);
        vector <int> pos(n + 1);
        vector <int> vis(n + 1, 1);

        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            pos[v[i]] = i;
        }
        if (v[1] < v[n])
        {
            cout << "YES\n";
            continue;
        }
        else
        {
            cout << "NO\n";
            continue;
        }
        bool sw = 1;
        vector <int> ans;
        int prev = -1;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                prev = ans.size();
                ans.push_back(1);
                int mx = 0;
                for (int j = i + 1; j <= n; j++)
                    mx = max(mx, v[j]);
                ans.push_back(mx);
                sw = 0;
                break;
            }
            if (vis[i])
            {
                vis[i] = 0;
                for (int j = i + 1; j <= n; j++)
                {
                    if (v[i] < v[j] && vis[j - 1] == 0)
                        vis[j] = 0, sw = 0;
                }
                ans.push_back(v[i]);
            }
            if (sw)
                break;
        }
        if (v[1] == 1)
            cout << "YES\n";
        else if (sw || v[n] == 1)
        {
            cout << "NO\n";
        }
        else
        {
            // cout << prev << "[\n";
            // for (int x : ans)
            //     cout << x << " ";
            // cout << "\n";
            int mx = 0;
            bool flag = 1;
            for (int i = 0; i < prev - 1; i++)
                if (v[i] > v[i + 1])
                    flag = 0;

            if (flag && ans[prev - 1] < ans[prev + 1])
                cout << "YES\n";
            else
                cout << "NO\n";
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;
int main()
{
    int t;  cin >> t;
    while (t--)
    {
        int n;  cin >> n;
        vector <int> v(n + 1);
        vector <int> pos(n + 1);
        vector <int> vis(n + 1, 1);

        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            pos[v[i]] = i;
        }
        bool sw = 1;
        vector <int> ans;
        int prev = -1;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                prev = ans.size();
                ans.push_back(1);
                int mx = 0;
                for (int j = i + 1; j <= n; j++)
                    mx = max(mx, v[j]);
                ans.push_back(mx);
                sw = 0;
                break;
            }
            if (vis[i])
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (v[i] < v[j])
                        vis[j] = 0, sw = 0;
                }
                ans.push_back(v[i]);
                vis[i] = 0;
            }
            if (sw)
                break;
        }
        if (v[1] == 1)
            cout << "YES\n";
        else if (sw || v[n] == 1)
        {
            cout << "NO\n";
        }
        else
        {
            // cout << prev << "[\n";
            // for (int x : ans)
            //     cout << x << " ";
            // cout << "\n";
            int mx = 0;
            for (int i = 0; i < prev; i++)
                mx = max(mx, ans[i]);

            if (mx < ans[ans.size() - 1])
                cout << "YES\n";
            else
                cout << "NO\n";
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;
int main()
{
    int t;  cin >> t;
    while (t--)
    {
        int n;  cin >> n;
        vector <int> v(n + 1);
        vector <int> pos(n + 1);
        vector <int> vis(n + 1, 1);

        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            pos[v[i]] = i;
        }
        bool sw = 1;
        vector <int> ans;
        int prev = -1;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                prev = ans.size();
                ans.push_back(1);
                int mx = 0;
                for (int j = i + 1; j <= n; j++)
                    mx = max(mx, v[j]);
                ans.push_back(mx);
                sw = 0;
                break;
            }
            if (vis[i])
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (v[i] < v[j])
                        vis[j] = 0, sw = 0;
                }
                ans.push_back(v[i]);
            }
            if (sw)
                break;
        }
        if (v[1] == 1)
            cout << "YES\n";
        else if (sw || v[n] == 1)
        {
            cout << "NO\n";
        }
        else
        {
            bool flag = 1;
            // cout << prev << "[\n";
            // for (int x : ans)
            //     cout << x << " ";
            // cout << "\n";
            int mx = 0;
            for (int i = 0; i < prev; i++)
                mx = max(mx, ans[i]);

            if (mx < ans[ans.size() - 1])
                cout << "YES\n";
            else
                cout << "NO\n";
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;
int main()
{
    int t;  cin >> t;
    while (t--)
    {
        int n;  cin >> n;
        vector <int> v(n + 1);
        vector <int> pos(n + 1);
        vector <int> vis(n + 1, 1);

        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            pos[v[i]] = i;
        }
        bool sw = 1;
        vector <int> ans;
        int prev = -1;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                prev = ans.size();
                ans.push_back(1);
                for (int j = i + 1; j <= n; j++)
                    ans.push_back(v[j]);
                sw = 0;
                break;
            }
            if (vis[i])
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (v[i] < v[j])
                        vis[j] = 0, sw = 0;
                }
                ans.push_back(v[i]);
            }
            if (sw)
                break;
        }
        if (v[1] == 1)
            cout << "YES\n";
        else if (sw || v[n] == 1)
        {
            cout << "NO\n";
        }
        else
        {
            bool flag = 1;
            // cout << prev << "[\n";
            // for (int x : ans)
            //     cout << x << " ";
            // cout << "\n";
            for (int i = 0; i < prev; i++)
            {
                bool check = 1;
                for(int j = prev + 1; j < ans.size(); j++)
                {
                    if (ans[i] < ans[j])
                    {
                        check = 0;
                        break;
                    }
                }
                if (check)
                {
                    flag = 0;
                    cout << "NO\n"; break;

                }
            }
            if (flag)
                cout << "YES\n";
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;
int main()
{
    int t;  cin >> t;
    while (t--)
    {
        int n;  cin >> n;
        vector <int> v(n + 1);
        vector <int> pos(n + 1);
        vector <int> vis(n + 1, 1);
        for (int i = 1; i < n + 1; i++)
        {
            cin >> v[i];
            pos[v[i]] = i;
        }
        bool sw = 1;
        vector <int> ans;
        int prev = -1;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                prev = ans.size();
                ans.push_back(1);
                for (int j = i + 1; j < n; j++)
                    ans.push_back(v[j]);
                sw = 0;
                break;
            }
            if (vis[i])
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (v[i] < v[j])
                        vis[j] = 0, sw = 0;
                }
                ans.push_back(v[i]);
            }
            if (sw)
                break;
        }
        if (sw || v[n] == 1)
        {
            cout << "NO\n";
        }
        else
        {
            bool flag = 1;
            for (int i = 0; i < prev; i++)
            {
                bool check = 1;
                for(int j = prev + 1; j < ans.size(); j++)
                {
                    if (v[i] < v[j])
                    {
                        check = 0;
                        break;
                    }
                }
                if (check)
                {
                    flag = 0;
                    cout << "NO\n"; break;

                }
            }
            if (flag)
                cout << "YES\n";
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;
int main()
{
    int t;  cin >> t;
    while (t--)
    {
        int n;  cin >> n;
        vector <int> v(n + 1);
        vector <int> pos(n + 1);
        vector <int> vis(n + 1, 1);

        // vector <int> v(n + 1);
        // vector <int> pos(n + 1);
        // vector <int> vis(n + 1, 1);

        // vector <int> v(n + 1);
        // vector <int> pos(n + 1);
        // vector <int> vis(n + 1, 1);

        // vector <int> v(n + 1);
        // vector <int> pos(n + 1);
        // vector <int> vis(n + 1, 1);
        for (int i = 1; i < n + 1; i++)
        {
            cin >> v[i];
            pos[v[i]] = i;
        }
        bool sw = 1;
        vector <int> ans;
        int prev = -1;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                prev = ans.size();
                ans.push_back(1);
                for (int j = i + 1; j < n; j++)
                    ans.push_back(v[j]);
                sw = 0;
                break;
            }
            if (vis[i])
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (v[i] < v[j])
                        vis[j] = 0, sw = 0;
                }
                ans.push_back(v[i]);
            }
            if (sw)
                break;
        }
        if (sw || v[n] == 1)
        {
            cout << "NO\n";
        }
        else
        {
            bool flag = 1;
            for (int i = 0; i < prev; i++)
            {
                bool check = 1;
                for(int j = prev + 1; j < ans.size(); j++)
                {
                    if (v[i] < v[j])
                    {
                        check = 0;
                        break;
                    }
                }
                if (check)
                {
                    flag = 0;
                    cout << "NO\n"; break;

                }
            }
            if (flag)
                cout << "YES\n";
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;
int main()
{
    int t;  cin >> t;
    while (t--)
    {
        int n;  cin >> n;
        vector <int> v(n + 1);
        vector <int> pos(n + 1);
        vector <int> vis(n + 1, 1);

        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            pos[v[i]] = i;
        }
        bool sw = 1;
        vector <int> ans;
        int prev = -1;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                prev = ans.size();
                ans.push_back(1);
                for (int j = i + 1; j < n; j++)
                    ans.push_back(v[j]);
                sw = 0;
                break;
            }
            if (vis[i])
            {
                for (int j = i + 1; j <= n; j++)
                {
                    if (v[i] < v[j])
                        vis[j] = 0, sw = 0;
                }
                ans.push_back(v[i]);
            }
            if (sw)
                break;
        }
        if (v[1] == 1)
            cout << "YES\n";
        else if (sw || v[n] == 1)
        {
            cout << "NO\n";
        }
        else
        {
            bool flag = 1;
            // cout << prev << "[\n";
            // for (int x : ans)
            //     cout << x << " ";
            // cout << "\n";
            for (int i = 0; i < prev; i++)
            {
                bool check = 1;
                for(int j = prev + 1; j < ans.size(); j++)
                {
                    if (ans[i] < ans[j])
                    {
                        check = 0;
                        break;
                    }
                }
                if (check)
                {
                    flag = 0;
                    cout << "NO\n"; break;

                }
            }
            if (flag)
                cout << "YES\n";
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;
int main()
{
    int t;  cin >> t;
    while (t--)
    {
        int n;  cin >> n;
        vector <int> v(n + 1);
        vector <int> pos(n + 1);
        vector <int> vis(n + 1, 1);

        for (int i = 1; i <= n; i++)
        {
            cin >> v[i];
            pos[v[i]] = i;
        }
        bool sw = 1;
        vector <int> ans;
        int prev = -1;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                prev = ans.size();
                ans.push_back(1);
                int mx = 0;
                for (int j = i + 1; j <= n; j++)
                    mx = max(mx, v[j]);
                ans.push_back(mx);
                sw = 0;
                break;
            }
            if (vis[i])
            {
                vis[i] = 0;
                for (int j = i + 1; j <= n; j++)
                {
                    if (v[i] < v[j] && vis[j - 1] == 0)
                        vis[j] = 0, sw = 0;
                }
                ans.push_back(v[i]);
            }
            if (sw)
                break;
        }
        if (v[1] == 1)
            cout << "YES\n";
        else if (sw || v[n] == 1)
        {
            cout << "NO\n";
        }
        else
        {
            // cout << prev << "[\n";
            // for (int x : ans)
            //     cout << x << " ";
            // cout << "\n";
            int mx = 0;
            bool flag = 1;
            for (int i = 0; i < prev - 1; i++)
                if (v[i] > v[i + 1])
                    flag = 0;

            if (flag && ans[prev - 1] < ans[prev + 1])
                cout << "YES\n";
            else
                cout << "NO\n";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

/*

19999
10
10 5 8 3 6 1 9 4 7 2
10
9 4 6 1 8 3 10 5 7 2
5
3 4 1 5 2
3
2 1 3
3
2 1 3
5
1 4 2 5 3

*/
int main()
{
    int test;
    cin>>test;

    while(test--){

       int n,a;
       cin>>n;

       vector<int> input;

       for(int i=1; i<=n; i++){
           cin>>a;
           input.push_back(a);

       }

       stack<int> value;
       value.push(input[0]);

       for(int i=1; i<n; i++){
          //cout<<value.top()<<" :: "<<value.size()<<endl;

          if(value.top()>input[i]) value.push(input[i]);
          else if(value.size()>1 and value.top()<input[i]){
              while(value.top()<input[i]){
                //cout<<value.top()<<" * ";

                value.pop();
                if(value.empty()) break;
                //cout<<"*"<<endl;
              }
              //cout<<endl;
            value.push(input[i]);

          }
       }

     if(value.size()==1){
        cout<<"YES"<<endl;
     }
     else cout<<"NO"<<endl;

       vector<int> res;

       while(!value.empty()){

           res.push_back(value.top());
           cout<<value.top()<<" ";
           value.pop();
       }

       cout<<endl;

//
//       reverse(res.begin(),res.end());
//
//       for(int i=0; i<res.size(); i++)
//        cout<<res[i]<<" ";
//
//       cout<<endl;
//
//       if(is_sorted(res.begin(),res.end())){
//        cout<<"YES"<<endl;
//       }
//       else cout<<"NO"<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

/*

19999
10
10 5 8 3 6 1 9 4 7 2
10
9 4 6 1 8 3 10 5 7 2
5
3 4 1 5 2
3
2 1 3
3
2 1 3
5
1 4 2 5 3

20000
27
27 25 23 21 19 17 15 13 11 9 7 5 3 1 2 4 6 8 10 12 14 16 18 20 22 24 26
12
1 3 5 7 9 11 12 10 8 6 4 2
6
5 3 1 2 4 6
9
7 2 5 6 1 9 4 8 3
6
5 3 1 2 4 6
9
4 9 1 6 5 3 8 2 7

NO
YES
YES
NO
YES
YES

*/
int main()
{
    int test;
    cin>>test;

    while(test--){

       int n,a;
       cin>>n;

       vector<int> input;

       for(int i=1; i<=n; i++){
           cin>>a;
           input.push_back(a);

       }

       stack<int> value;
       value.push(input[0]);

       for(int i=1; i<n; i++){

           int flag = 0;

           while(value.top()<input[i]){
                //cout<<value.size()<<endl;
                if(value.size()>1) value.pop();
                else{
                    flag = 1;
                    break;
                }

                if(value.empty()) break;
           }

           if(flag == 0) value.push(input[i]);

          }

     if(value.size()==1){
        cout<<"YES"<<endl;
     }
     else cout<<"NO"<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

/*

19999
10
10 5 8 3 6 1 9 4 7 2
10
9 4 6 1 8 3 10 5 7 2
5
3 4 1 5 2
3
2 1 3
3
2 1 3
5
1 4 2 5 3

*/
int main()
{
    int test;
    cin>>test;

    while(test--){

       int n,a;
       cin>>n;

       vector<int> input;

       for(int i=1; i<=n; i++){
           cin>>a;
           input.push_back(a);

       }

       stack<int> value;
       value.push(input[0]);

       for(int i=1; i<n; i++){
          //cout<<value.top()<<" :: "<<value.size()<<endl;

          if(value.top()>input[i]) value.push(input[i]);
          else if(value.size()>1 and value.top()<input[i]){
            value.pop();
            value.push(input[i]);

          }
       }

       vector<int> res;

       while(!value.empty()){

           res.push_back(value.top());
           //cout<<value.top()<<" ";
           value.pop();
       }

       //cout<<endl;
       int check = 0;
       reverse(res.begin(),res.end());
       for(int i=0; i<res.size()-1; i++){
          if(res[i]>res[i+1]){
            cout<<"NO"<<endl;
            check = 1;
            break;
          }
       }

       if(check==0){
        cout<<"YES"<<endl;
       }

    }

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int test;
    cin>>test;

    while(test--){

       int n,a;
       cin>>n;

       vector<int> input;

       for(int i=1; i<=n; i++){
           cin>>a;
           input.push_back(a);

       }

       int flag = 0, pos = 0, minn=1<<28, maxx = 0;
       for(int i=0; i<n; i++){

          if(i==0 and input[i]==n){
            flag = 1;
            cout<<"NO"<<endl;
            break;
          }
          else if(i==0 and input[i]==1){
            flag = 1;
            cout<<"YES"<<endl;
            break;
          }
          else if(i+1==n and input[i]==1){
            flag = 1;
            cout<<"NO"<<endl;
            break;
          }

          if(input[i]==1){
            pos = 1;
          }

          if(pos==0){
            minn = min(input[i],minn);
          }
          else{
            maxx = max(input[i],maxx);
          }

       }

       if(flag==0){

           if(minn<maxx){
            cout<<"YES"<<endl;
           }
           else cout<<"NO"<<endl;

       }

    }

}


#include<bits/stdc++.h>
using namespace std;

/*

19999
10
10 5 8 3 6 1 9 4 7 2
10
9 4 6 1 8 3 10 5 7 2
5
3 4 1 5 2
3
2 1 3
3
2 1 3
5
1 4 2 5 3

*/
int main()
{
    int test;
    cin>>test;

    while(test--){

       int n,a;
       cin>>n;

       vector<int> input;

       for(int i=1; i<=n; i++){
           cin>>a;
           input.push_back(a);

       }

       stack<int> value;
       value.push(input[0]);

       for(int i=1; i<n; i++){
          //cout<<value.top()<<" :: "<<value.size()<<endl;

          if(value.top()>input[i]) value.push(input[i]);
          else if(value.size()>1 and value.top()<input[i]){
              while(value.top()<input[i]){
                //cout<<value.top()<<" * ";

                value.pop();
                if(value.empty()) break;
                //cout<<"*"<<endl;
              }
              //cout<<endl;
            value.push(input[i]);

          }
       }

     if(value.size()==1){
        cout<<"YES"<<endl;
     }
     else cout<<"NO"<<endl;

//       vector<int> res;
//
//       while(!value.empty()){
//
//           res.push_back(value.top());
//           cout<<value.top()<<" ";
//           value.pop();
//       }
//
//       cout<<endl;

//
//       reverse(res.begin(),res.end());
//
//       for(int i=0; i<res.size(); i++)
//        cout<<res[i]<<" ";
//
//       cout<<endl;
//
//       if(is_sorted(res.begin(),res.end())){
//        cout<<"YES"<<endl;
//       }
//       else cout<<"NO"<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

/*

19999
10
10 5 8 3 6 1 9 4 7 2
10
9 4 6 1 8 3 10 5 7 2
5
3 4 1 5 2
3
2 1 3
3
2 1 3
5
1 4 2 5 3

20000
27
27 25 23 21 19 17 15 13 11 9 7 5 3 1 2 4 6 8 10 12 14 16 18 20 22 24 26
12
1 3 5 7 9 11 12 10 8 6 4 2
6
5 3 1 2 4 6
9
7 2 5 6 1 9 4 8 3
6
5 3 1 2 4 6
9
4 9 1 6 5 3 8 2 7

NO
YES
YES
NO
YES
YES

*/
int main()
{
    int test;
    cin>>test;

    while(test--){

       int n,a;
       cin>>n;

       vector<int> input;

       for(int i=1; i<=n; i++){
           cin>>a;
           input.push_back(a);

       }

       stack<int> value;
       value.push(input[0]);

       for(int i=1; i<n; i++){

           int flag = 0;

           while(value.top()<input[i]){
                cout<<value.size()<<endl;
                if(value.size()>1) value.pop();
                else{
                    flag = 1;
                    break;
                }

                if(value.empty()) break;
           }

           if(flag == 0) value.push(input[i]);

          }

     if(value.size()==1){
        cout<<"YES"<<endl;
     }
     else cout<<"NO"<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;

/*

19999
10
10 5 8 3 6 1 9 4 7 2
10
9 4 6 1 8 3 10 5 7 2
5
3 4 1 5 2
3
2 1 3
3
2 1 3
5
1 4 2 5 3

20000
27
27 25 23 21 19 17 15 13 11 9 7 5 3 1 2 4 6 8 10 12 14 16 18 20 22 24 26
12
1 3 5 7 9 11 12 10 8 6 4 2
6
5 3 1 2 4 6
9
7 2 5 6 1 9 4 8 3
6
5 3 1 2 4 6
9
4 9 1 6 5 3 8 2 7

NO
YES
YES
NO
YES
YES

*/
int main()
{
    int test;
    cin>>test;

    while(test--){

       int n,a;
       cin>>n;

       vector<int> input;

       for(int i=1; i<=n; i++){
           cin>>a;
           input.push_back(a);

       }

       stack<int> value;
       value.push(input[0]);

       for(int i=1; i<n; i++){
          //cout<<value.top()<<" :: "<<value.size()<<endl;

          if(value.top()>input[i]) value.push(input[i]);
          else if(value.size()>1 and value.top()<input[i]){
                  int minn = 1<<28;

                  value.pop();

              while(value.top()<input[i]){
                minn = min(minn,value.top());
                value.pop();
                if(value.empty()) break;

              }
              //cout<<endl;

            value.push(min(minn,input[i]));

          }
       }

     if(value.size()==1){
        cout<<"YES"<<endl;
     }
     else cout<<"NO"<<endl;

//
//       vector<int> res;
//
//       while(!value.empty()){
//
//           res.push_back(value.top());
//           cout<<value.top()<<" ";
//           value.pop();
//       }
//
//       cout<<endl;

//
//       reverse(res.begin(),res.end());
//
//       for(int i=0; i<res.size(); i++)
//        cout<<res[i]<<" ";
//
//       cout<<endl;
//
//       if(is_sorted(res.begin(),res.end())){
//        cout<<"YES"<<endl;
//       }
//       else cout<<"NO"<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 998244353
#define pii pair<int, int>
long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}
#define pow expo
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#define T int _;cin>>_;while(_--)

//map<char, vector<int> >m;

int n;
int arr[1005];

int mex(){
	int freq[1005];
	fill(freq, freq+1005, 0);
	for(all){
		freq[arr[i]]++;
	}
	for(int i=0; i<=n; i++){
		if(freq[i]==0){
			return i;
		}
	}
}

int32_t main(){
	Nirvana;
	T{

		cin>>n;

		deque<int>q;
		for(all){
			int x;
			cin>>x;
			if(q.size()==0){
				q.push_back(x);
				continue;
			}

			while(true){
				if(q.size()==1 || x <= q.back()){
					q.push_back(x);
					break;
				}
				else q.pop_back();
			}

		}
		if(q.size()==1){
			cout<<"YES"<<endl;
		}
		else if(q.back() > q.front()){
			cout<<"YES"<<endl;
		}
		else cout<<"NO"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 998244353
#define pii pair<int, int>
long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}
#define pow expo
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#define T int _;cin>>_;while(_--)

//map<char, vector<int> >m;
int n,m;
int valid(int i, int j){
	if(i<0 || i>n-1 || j<0 || j>m-1)return 0;
	return 1;
}

int32_t main(){
	Nirvana;
	T{
		int n;
		cin>>n;

		for(all)cin>>arr[i];

		if(arr[0] < arr[n-1])cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 998244353
#define pii pair<int, int>
long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}
#define pow expo
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#define T int _;cin>>_;while(_--)

//map<char, vector<int> >m;
int n,m;
int valid(int i, int j){
	if(i<0 || i>n-1 || j<0 || j>m-1)return 0;
	return 1;
}

int32_t main(){
	Nirvana;
	T{
		int n;
		cin>>n;
		int arr[n];

		for(all)cin>>arr[i];

		if(arr[0] < arr[n-1])cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 998244353
#define pii pair<int, int>
long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}
#define pow expo
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#define T int _;cin>>_;while(_--)

//map<char, vector<int> >m;
int n,m;
int valid(int i, int j){
	if(i<0 || i>n-1 || j<0 || j>m-1)return 0;
	return 1;
}

int32_t main(){
	Nirvana;
	T{
		int n;
		cin>>n;
		int arr[n];
		int mini[n];
		int maxi[n];

		for(all)cin>>arr[i];

		mini[0] = arr[0];
		maxi[n-1] = arr[n-1];

		for(int i=1; i<n; i++){
			mini[i] = min(mini[i-1], arr[i]);
		}
		for(int i=n-2; i>=0; i--){
			maxi[i] = max(maxi[i+1], arr[i]);
		}
		int flag = 1;
		for(int i=0; i<n-1; i++){
			if(mini[i] > maxi[i+1]){
				flag=0;
			}
		}
		if(flag)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 998244353
#define pii pair<int, int>
long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}
#define pow expo
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#define T int _;cin>>_;while(_--)

//map<char, vector<int> >m;
int n,m;
int valid(int i, int j){
	if(i<0 || i>n-1 || j<0 || j>m-1)return 0;
	return 1;
}

int32_t main(){
	Nirvana;
	T{
		int n;
		cin>>n;

		for(all)cin>>arr[i];

		if(a[0] < a[n-1])cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 998244353
#define pii pair<int, int>
long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}
#define pow expo
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#define T int _;cin>>_;while(_--)

//map<char, vector<int> >m;

int n;
int arr[1005];

int mex(){
	int freq[1005];
	fill(freq, freq+1005, 0);
	for(all){
		freq[arr[i]]++;
	}
	for(int i=0; i<=n; i++){
		if(freq[i]==0){
			return i;
		}
	}
}

int32_t main(){
	Nirvana;
	T{

		cin>>n;

		deque<int>q;
		for(all){
			int x;
			cin>>x;
			if(q.size()==0){
				q.push_back(x);
				continue;
			}

			while(true){
				if(q.size()==1 && x>q.back())break;
				if(q.size()==1 && x<q.back()){
					q.push_back(x);
					break;
				}
				if(q.size() > 1){
					if(x < q.back()){
						q.push_back(x);
						break;
					}
					else q.pop_back();
				}

			}

		}
		if(q.size()==1){
			cout<<"YES"<<endl;
		}
		else if(q.back() > q.front()){
			cout<<"YES"<<endl;
		}
		else cout<<"NO"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 998244353
#define pii pair<int, int>
long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}
#define pow expo
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#define T int _;cin>>_;while(_--)

//map<char, vector<int> >m;

int n;
int arr[1005];

int mex(){
	int freq[1005];
	fill(freq, freq+1005, 0);
	for(all){
		freq[arr[i]]++;
	}
	for(int i=0; i<=n; i++){
		if(freq[i]==0){
			return i;
		}
	}
}

int32_t main(){
	Nirvana;
	T{

		cin>>n;

		deque<int>q;
		for(all){
			int x;
			cin>>x;
			if(q.size()==0){
				q.push_back(x);
				continue;
			}

			while(true){
				if(q.size()==1 && x>q.back())break;
				if(q.size()==1 && x <= q.back()){
					q.push_back(x);
					break;
				}
				else q.pop_back();
			}

		}
		if(q.size()==1){
			cout<<"YES"<<endl;
		}
		else if(q.back() > q.front()){
			cout<<"YES"<<endl;
		}
		else cout<<"NO"<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef pair<int,int> pii;
typedef long long int ll;
typedef tree<pii,null_type,less<pii>,rb_tree_tag, \
tree_order_statistics_node_update> ordered_set;

#define int ll
#define long int
#define pb push_back
#define all int i=0; i<n; i++
#define INF 4e18

#define Nirvana ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 998244353
#define pii pair<int, int>
long expo(long base, long exp)
{
    long t = 1L;
    while (exp > 0)
    {
        if (exp % 2 != 0)  t = (t * base);
        base = (base * base);
        exp /= 2;
    }
    return t;
}
#define pow expo
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#define T int _;cin>>_;while(_--)

//map<char, vector<int> >m;
int n,m;
int valid(int i, int j){
	if(i<0 || i>n-1 || j<0 || j>m-1)return 0;
	return 1;
}

int32_t main(){
	Nirvana;
	T{
		int n;
		cin>>n;
		int arr[n];
		int mini[n];
		int maxi[n];

		for(all)cin>>arr[i];

		mini[0] = arr[0];
		maxi[n-1] = arr[n-1];

		for(int i=1; i<n; i++){
			mini[i] = min(mini[i-1], arr[i]);
		}
		for(int i=n-2; i>=0; i--){
			maxi[i] = max(maxi[i+1], arr[i]);
		}
		int flag = 0;
		for(int i=0; i<n-1; i++){
			if(mini[i] < maxi[i+1]){
				flag=1;
			}
		}
		if(flag)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007

void solve()
{
	int n,count=0;
	set <ll,greater<ll>> s;
	cin>>n;
	ll a[n],b[n],x,y;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=n-1;i>=0;i--)
	{

		x = *s.begin();
		if(x < a[i]) count++;
		s.insert(a[i]);
		if(count>2) break;
	}
	if(a[n-1]==1)
	{
		if(count>=2) cout<<"NO\n";
		else cout<<"YES\n";
	}
	else
	{
		if(count>2) cout<<"NO\n";
		else cout<<"YES\n";
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007

void solve()
{
	int n,count=0;
	set <ll,greater<ll>> s;
	cin>>n;
	ll a[n],x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=n-1;i>=0;i--)
	{
		x = *s.begin();
		if(x < a[i]) count++;
		s.insert(a[i]);
		if(count>2) break;
	}
	if(n>1 && (a[n-1]==1 || a[0]==n)) cout<<"NO\n";
	else
	{
		if(count>2) cout<<"NO\n";
		else cout<<"YES\n";
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007

void solve()
{
	ll n,count=0;
	cin>>n;
	ll a[n],x=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(ll i=n-1;i>=0;i--)
	{
		if(x < a[i]) count++;
		else count--;
		x = max(x,a[i]);
	}
	if(a[n-1]==1 || a[0]==n) cout<<"NO\n";
	else
	{
		if(count>2) cout<<"NO\n";
		else cout<<"YES\n";
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007

void solve()
{
	int n,count=0;
	set <ll,greater<ll>> s;
	cin>>n;
	ll a[n],b[n],x,y;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=n-1;i>=0;i--)
	{

		x = *s.begin();
		if(x < a[i]) count++;
		s.insert(a[i]);
		if(count>2) break;
	}
	cout<<a[n-1]<<endl;
	if(a[n-1]==1)
	{
		if(count>=2) cout<<"NO\n";
		else cout<<"YES\n";
	}
	else
	{
		if(count>2) cout<<"NO\n";
		else cout<<"YES\n";
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007

void solve()
{
	int n,count=0;
	set <ll,greater<ll>> s;
	cin>>n;
	ll a[n],x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=n-1;i>=0;i--)
	{

		x = *s.begin();
		if(x < a[i]) count++;
		s.insert(a[i]);
		if(count>2) break;
	}
	if(a[n-1]==1)
	{
		if(count>=2) cout<<"NO\n";
		else cout<<"YES\n";
	}
	else
	{
		if(count>2) cout<<"NO\n";
		else cout<<"YES\n";
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007

void solve()
{
	int n,count=0;
	set <ll,greater<ll>> s;
	cin>>n;
	ll a[n],x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=n-1;i>=0;i--)
	{

		x = *s.begin();
		if(x < a[i]) count++;
		s.insert(a[i]);
		if(count>2) break;
	}
	cout<<count<<endl;
	if(a[n-1]==1)
	{
		if(count>=2) cout<<"NO\n";
		else cout<<"YES\n";
	}
	else
	{
		if(count>2) cout<<"NO\n";
		else cout<<"YES\n";
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007

void solve()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	if(a[0]>a[n-1]) cout<<"NO\n";
	else cout<<"YES\n";
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007

void solve()
{
	int n,count=0;
	set <ll,greater<ll>> s;
	cin>>n;
	ll a[n],b[n],x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=n-1;i>=0;i--)
	{

		x = *s.begin();
		if(x < a[i]) count++;
		s.insert(a[i]);
		if(count>2) break;
	}
	if(a[n-1]==1)
	{
		if(count>=2) cout<<"NO\n";
		else cout<<"YES\n";
	}
	else
	{
		if(count>2) cout<<"NO\n";
		else cout<<"YES\n";
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll t,n,x,y,a,b,m,i;
   cin>>t;
   while(t--)
   {
     cin>>n;
     vector<ll>p;
     x=INT_MAX;
     y=0;
     for(i=0;i<n;i++)
     {
         cin>>m;
         p.push_back(m);
         x=min(x,m);
         y=max(y,m);
     }
     if(x==p[0]||y==p[n-1])
        cout<<"YES"<<endl;
    else if(x==p[n-1]||y==p[0]||p[n-1]==x+1)
        cout<<"NO"<<endl;
     else
        cout<<"YES"<<endl;
   }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll t,n,x,y,a,b,m,i;
   cin>>t;
   while(t--)
   {
     cin>>n;
     vector<ll>p;
     x=INT_MAX;
     y=0;
     for(i=0;i<n;i++)
     {
         cin>>m;
         p.push_back(m);
         x=min(x,m);
         y=max(y,m);
     }
     if(x==p[0]||y==p[n-1])
        cout<<"YES"<<endl;
    else if(x==p[n-1]||y==p[0])
        cout<<"NO"<<endl;
     else
        cout<<"YES"<<endl;
   }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll t,n,x,y,a,b,m,i;
   cin>>t;
   while(t--)
   {
     cin>>n;
     vector<ll>p;
     x=INT_MAX;
     y=0;
     for(i=0;i<n;i++)
     {
         cin>>m;
         p.push_back(m);
     }
     if(p[0]|==1||p[n-1]==n){
        cout<<"YES"<<endl;
        continue;}
    else if(p[n-1]==1||p[0]==n){
        cout<<"NO"<<endl;
        continue;}
       if(p[0]<p[n-1])
        cout<<"YES"<<endl;
       else
        cout<<"NO"<<endl;
   }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll t,n,x,y,a,b,m,i;
   cin>>t;
   while(t--)
   {
     cin>>n;
     vector<ll>p;
     x=INT_MAX;
     y=0;
     for(i=0;i<n;i++)
     {
         cin>>m;
         p.push_back(m);
         x=min(x,m);
         y=max(y,m);
     }
     if(x==p[0]||y==p[n-1]){
        cout<<"YES"<<endl;
        continue;}
    else if(x==p[n-1]||y==p[0]){
        cout<<"NO"<<endl;
        continue;}
        y=n/2;
        a=0;
        b=0;
        for(i=0;i<y-1;i++)
        {
            if(p[i]<p[i+1])
                a++;
        }
        for(i=y;i<n-1;i++)
        {
            if(p[i]<p[i+1])
                b++;
        }
       if((a+b)==n-2)
        cout<<"YES"<<endl;
       else
        cout<<"NO"<<endl;
   }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll t,n,x,y,a,b,m,i;
   cin>>t;
   while(t--)
   {
     cin>>n;
     vector<ll>p;
     x=INT_MAX;
     y=0;
     for(i=0;i<n;i++)
     {
         cin>>m;
         p.push_back(m);
     }
     if(p[0]==1||p[n-1]==n){
        cout<<"YES"<<endl;
        continue;}
    else if(p[n-1]==1||p[0]==n){
        cout<<"NO"<<endl;
        continue;}
       if(p[0]<p[n-1])
        cout<<"YES"<<endl;
       else
        cout<<"NO"<<endl;
   }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll t,n,x,y,a,b,m,i;
   cin>>t;
   while(t--)
   {
     cin>>n;
     vector<ll>p;
     x=INT_MAX;
     y=0;
     for(i=0;i<n;i++)
     {
         cin>>m;
         p.push_back(m);
         x=min(x,m);
         y=max(y,m);
     }
     if(x==p[n-1]||y==p[0])
        cout<<"NO"<<endl;
     else
        cout<<"YES"<<endl;
   }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case() {
	int n; cin >> n;
	vector<int> hash(n);
	for(int &x : hash)
		cin >> x;
	if(hash[0] < hash[n-1])
		cout << "NO\n";
	else
		cout << "YES\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin >> T;
	while(T--){
		test_case();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case() {
	int n; cin >> n;
	vector<int> hash(n);
	int count1 = 0, count2 = 0;
	for(int &x : hash)
		cin >> x;
	for(int i = 0 ; i < n-1 ; i++){
		if(hash[i+1] > hash[i])
			count1++;
		else
			count2++;
	}
	count1 = min(count1,count2);
	if(count1 < n/2)
		cout<<"YES\n";
	else
		cout<<"NO\n";

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin >> T;
	while(T--){
		test_case();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case() {
	int n; cin >> n;
	vector<int> hash(n);
	for(int &x : hash)
		cin >> x;
	if(hash[0] < hash[n-1])
		cout << "YES\n";
	else
		cout << "NO\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin >> T;
	while(T--){
		test_case();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case() {
	int n; cin >> n;
	vector<int> hash(n);
	for(int &x : hash)
		cin >> x;
	int k = 0;
	int index = -1;
	if(hash[1] < hash[0])
		index = 0,k=hash[0];
	if(hash[n-1] < hash[n-2])
		index = n-2,k=hash[n-2];
	for(int i = 1 ; i < n-1 ; i++){
		if(hash[i+1] < hash[i] && hash[i-1] > hash[i]){
			k = max(k,hash[i]);
			index = i;
		}
	}
	//~ cout<<index<<" "<<k<<"\n";
	if(index==-1){
		cout<<"YES\n";
		return;
	}
	bool ok = false;
	for(int i = index ; i < n ; i++){
		if(hash[i] > k)
			ok = true;
		}
	if(ok)
		cout<<"YES\n";
	else
		cout<<"NO\n";

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin >> T;
	while(T--){
		test_case();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case() {
	//~ int n; cin >> n;
	//~ vector<int> hash(n);
	//~ for(int &x : hash)
		//~ cin >> x;
	//~ vector<int> ne;
	//~ bool ok = true;
	//~ for(int i = 0 ; i < n ; i++){
		//~ if(ne.empty())
			//~ ne.push_back(hash[i]);
		//~ else if (hash[i] > ne.back()){
			//~ if(ok){
				//~ continue;
			//~ }
			//~ else{
				//~ if(hash[i] > ne.back()){
					//~ if((int)hash.size() == 2)
					//~ {
						//~ ok = true;
					//~ }
					//~ else{
						//~ ne.pop_back();
						//~ while(true)
						//~ {
							//~ if(ne.size() == 1)
							//~ {
								//~ ok = true;
								//~ break;
							//~ }
							//~ if(hash[i] > ne.back())
								//~ ne.pop_back();
							//~ else
								//~ break;
						//~ }
					//~ }
				//~ }
				//~ else
					//~ ne.push_back(hash[i]);
			//~ }
		//~ }
		//~ else{
			//~ ok = false;
			//~ ne.push_back(hash[i]);
		//~ }
	//~ }
	//~ if((int)ne.size()==1)
		//~ cout<<"YES\n";
	//~ else
		//~ cout<<"NO\n";
	int n; cin >> n;
	vector<int> hash(n);
	for(int &x : hash)
		cin >> x;
	if(hash[0] == n || hash[n-1] == 1)
		cout << "NO\n";
	else
		cout << "YES\n";

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin >> T;
	while(T--){
		test_case();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case() {
	int n; cin >> n;
	vector<int> hash(n);
	for(int &x : hash)
		cin >> x;
	vector<int> ne;
	bool ok = true;
	for(int i = 0 ; i < n ; i++){
		if(ne.empty())
			ne.push_back(hash[i]);
		else if (hash[i] > ne.back()){
			if(ok){
				continue;
			}
			else{
				//ne.pop_back();
				if(hash[i] > ne.back()){
					if((int)hash.size() == 2)
					{
						ok = true;
					}
					else{
						ne.pop_back();
						while(true)
						{
							if(ne.size() == 1)
							{
								ok = true;
								break;
							}
							if(hash[i] > ne.back())
								ne.pop_back();
							else
								break;
						}
					}
				}
				else
					ne.push_back(hash[i]);
			}
		}
		else{
			ok = false;
			ne.push_back(hash[i]);
		}
	}
	if((int)ne.size()==1)
		cout<<"YES\n";
	else
		cout<<"NO\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin >> T;
	while(T--){
		test_case();
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case() {
	int n; cin >> n;
	vector<int> hash(n);
	for(int &x : hash)
		cin >> x;
	vector<int> ne;
	bool ok = true;
	for(int i = 0 ; i < n ; i++){
		if(ne.empty())
			ne.push_back(hash[i]);
		else if (hash[i] > ne.back()){
			if(ok){
				continue;
			}
			else{
				ne.pop_back();
				if(hash[i] > ne.back())
					ok = true;
				else
					ne.push_back(hash[i]);
				}
		}
		else{
			ok = false;
			ne.push_back(hash[i]);
		}
	}
	if((int)ne.size()==1)
		cout<<"YES\n";
	else
		cout<<"NO\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin >> T;
	while(T--){
		test_case();
	}
}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{

	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<int>v(n);
		for(int i=0;i<n;i++)
		cin>>v[i];
		if(v[0]==n)
		cout<<"NO"<<endl;
		else
		{for(int i=0;i<v.size()-1;i++)
		{  if(v[i]<v[i+1])
		   {
			    if(i==0)
				{
					v.erase(v.begin()+(i+1));
					i=i-1;
				}
				else
	             {  v.erase(v.begin()+i);
	                i=i-2;
				  }

		   }

		}
		if(v.size()==1)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
		}

	}
	return 0;

}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{

	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<int>v(n);
		for(int i=0;i<n;i++)
		cin>>v[i];

		for(int i=0;i<v.size()-1;i++)
		{  if(v[i]<v[i+1])
		   {
			    if(i==0)
				{
					v.erase(v.begin()+(i+1));
					i=-1;
				}
				else
	             {  v.erase(v.begin()+i);
	                i=-1;
				  }

		   }

		}
		if(v.size()==1)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;

	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
        cin>>v[i];
        int sum=0;
        for(int i=1;i<n;i++)
        sum+=v[i]-v[i-1];

        if(sum<0)
        cout<<"NO"<<endl;
        else
        cout<<"YES"<<endl;
    }
    return 0;

}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<int>v(n);
		for(int i=0;i<n;i++)
		cin>>v[i];

		for(int i=0;i<n-1;i++)
		{
			if(v[i]<v[i+1])
			{
				if(v[i+2]<v[i+1])
			    {v.erase(v.begin()+(i+1));
			    i=-1;
				}
				else
				{v.erase(v.begin()+i);
				i=-1;
				}
			}

		}
		if(v.size()==1)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;

	}
	return 0;

}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{

	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<int>v(n);
		for(int i=0;i<n;i++)
		cin>>v[i];
		if(v[0]==n)
		cout<<"NO";
		else
		{for(int i=0;i<v.size()-1;i++)
		{  if(v[i]<v[i+1])
		   {
			    if(i==0)
				{
					v.erase(v.begin()+(i+1));
					i=i-1;
				}
				else
	             {  v.erase(v.begin()+i);
	                i=i-2;
				  }

		   }

		}
		if(v.size()==1)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
		}

	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int>v(n);
        for(int i=0;i<n;i++)
        cin>>v[i];
        int sum=0;
        for(int i=1;i<n;i++)
        sum+=v[i]-v[i-1];

        if(sum<0)
        cout<<"NO"<<endl;
        else
        cout<<"YES"<<endl;
    }
    return 0;

}


#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
	 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<int>v(n);
		for(int i=0;i<n;i++)
		cin>>v[i];

		for(int i=0;i<v.size()-1;i++)
		{  if(v[i]<v[i+1])
		   {
			    if(i==0)
				{
					v.erase(v.begin()+(i+1));
					i=i-1;
				}
				else
	             {  v.erase(v.begin()+i);
	                i=i-2;
				  }

		   }

		}
		if(v.size()==1)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;

	}
	return 0;

}