#include #include #include const int N = 1000000; int a[N]; bool v[N]; bool cmp(int i, int j) { if (a[i] != a[j]) { return a[i] < a[j]; } return i < j; } bool check(int n) { if (n == 1) { return true; } memset(v, 0, sizeof(*v) * n); int last = 0; if (cmp(1, 0)) { last = 1; } v[last] = true; for (int i = 1; i < n; ++ i) { int next = -1; for (int j = i - 1; j <= i + 1 && j < n; ++ j) { if (!v[j] && cmp(last, j) && (next == -1 || cmp(j, next))) { next = j; } } if (next == -1) { return false; } v[last = next] = true; } return true; } int main() { int T; assert(scanf("%d", &T) == 1); assert(1 <= T && T <= 10); for (int _ = 0; _ < T; ++ _) { int n; assert(scanf("%d", &n) == 1); assert(1 <= n && n <= N); for (int i = 0; i < n; ++ i) { assert(scanf("%d", a + i) == 1); assert(1 <= a[i] && a[i] <= 1000000000); } puts(check(n) ? "YES" : "NO"); } return 0; }