Monocarp had a tree which consisted of $n$ vertices and was rooted at vertex $1$. He decided to study BFS (Breadth-first search), so he ran BFS on his tree, starting from the root. BFS can be described by the following pseudocode:a = [] # the order in which vertices were processed

q = Queue()

q.put(1) # place the root at the end of the queue

while not q.empty():

    k = q.pop() # retrieve the first vertex from the queue

    a.append(k) # append k to the end of the sequence in which vertices were visited

    for y in g[k]: # g[k] is the list of all children of vertex k, sorted in ascending order

        q.put(y)



Monocarp was fascinated by BFS so much that, in the end, he lost his tree. Fortunately, he still has a sequence of vertices, in which order vertices were visited by the BFS algorithm (the array a from the pseudocode). Monocarp knows that each vertex was visited exactly once (since they were put and taken from the queue exactly once). Also, he knows that all children of each vertex were viewed in ascending order.

Monocarp knows that there are many trees (in the general case) with the same visiting order $a$, so he doesn't hope to restore his tree. Monocarp is okay with any tree that has minimum height.

The height of a tree is the maximum depth of the tree's vertices, and the depth of a vertex is the number of edges in the path from the root to it. For example, the depth of vertex $1$ is $0$, since it's the root, and the depth of all root's children are $1$.

Help Monocarp to find any tree with given visiting order $a$ and minimum height.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of vertices in the tree.

The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$; $a_i \neq a_j$; $a_1 = 1$) — the order in which the vertices were visited by the BFS algorithm.

It's guaranteed that the total sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case print the minimum possible height of a tree with the given visiting order $a$.


-----Example-----
Input
3
4
1 4 3 2
2
1 2
3
1 2 3

Output
3
1
1



-----Note-----

In the first test case, there is only one tree with the given visiting order:  [Image] 

In the second test case, there is only one tree with the given visiting order as well:  [Image] 

In the third test case, an optimal tree with the given visiting order is shown below:  [Image]

Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Tree algorithms

Graph algorithms

Shortest paths
Skill types: Greedy algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	nodes = dict()
	currentNode = 0
	nodes[1] = [0, set()]
	for i in range(len(arr) - 1):
		if arr[i + 1] > arr[i]:
			nodes[arr[i + 1]] = [nodes[arr[currentNode]][0] + 1, set()]
			nodes[arr[currentNode]][1].add(arr[i])
		else:
			currentNode += 1
			nodes[arr[i + 1]] = [nodes[arr[currentNode]][0] + 1, set()]
			nodes[arr[currentNode]][1].add(arr[i])
	ans = 0
	for node in nodes:
		if nodes[node][0] > ans:
			ans = nodes[node][0]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = [1]
	curr = 0
	for i in range(1, n):
		if a[i] > a[i - 1]:
			curr += 1
		else:
			p.append(curr)
			curr = 1
	if curr > 0:
		p.append(curr)
	d = 1
	curr = 0
	prev = 1
	i = 1
	while i < len(p):
		if prev == 0:
			prev = curr
			curr = 0
			d += 1
		prev -= 1
		curr += p[i]
		i += 1
	print(d)


N = 200005

def solve(n, a):
	b = [0] * N
	b[0] = 1
	m = 1
	l = 1
	while l < n:
		k = b[m - 1]
		b[m] = 0
		while k > 0:
			k -= 1
			if l == n:
				continue
			l += 1
			b[m] += 1
			while l < n and a[l] > a[l - 1]:
				l += 1
				b[m] += 1
		m += 1
	return m - 1
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))
	t -= 1


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		ans = 1
		level = {}
		i = 1
		k = 1
		while i < n:
			if a[i] > a[i - 1]:
				if k + 1 in level:
					level[k + 1] += 1
				elif k in level:
					level[k] += 1
				else:
					level[k] = 1
			elif level[k]:
				level[k] -= 1
				if k + 1 in level:
					level[k + 1] += 1
				else:
					level[k + 1] = 1
			else:
				k += 1
				level[k + 1] = 1
				level[k] -= 1
			i += 1
		print(max(level))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.append(float('-inf'))
	l = []
	x = 1
	for i in range(1, n):
		if a[i] < a[i + 1]:
			x += 1
			continue
		l.append(x)
		x = 1
	l.reverse()
	x = l.pop()
	h = 1
	while len(l) > 0:
		ans = 0
		while x > 0 and len(l) > 0:
			ans += l.pop()
			x -= 1
		h += 1
		x = ans
	print(h)


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		num_at_level = [1]
		curr_at_next_level = 0
		using = 1
		for i in range(1, n):
			if i == n - 1:
				num_at_level.append(curr_at_next_level + 1)
			elif a[i] < a[i + 1]:
				curr_at_next_level += 1
			elif using == num_at_level[-1]:
				using = 1
				num_at_level.append(curr_at_next_level + 1)
				curr_at_next_level = 0
			else:
				curr_at_next_level += 1
				using += 1
		print(len(num_at_level) - 1)
prog()


t = int(input())
for i in range(t):
	n = int(input())
	ordem = [int(a) for a in input().split()]
	arvore = [1]
	galho = 1
	for j in range(2, n):
		if ordem[j] > ordem[j - 1]:
			arvore[-1] = arvore[-1] + 1
		elif len(arvore) > 1 and galho < arvore[-2]:
			galho = galho + 1
			arvore[-1] = arvore[-1] + 1
		else:
			arvore.append(1)
			galho = 1
	print(len(arvore))


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(99999)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = collections.deque(map(int, input().split()))
	arr.popleft()
	level = 0
	cnt = 1
	while arr:
		nc = 0
		for i in range(cnt):
			p = float('-inf')
			if arr:
				while arr and arr[0] > p:
					p = arr.popleft()
					nc += 1
			else:
				break
		cnt = nc
		level += 1
	print(level)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	c = 1
	for i in range(2, n):
		if a[i] < a[i - 1]:
			l.append(c)
			c = 1
		else:
			c += 1
	l.append(c)
	l = list(reversed(l))
	ans = 1
	s = l.pop()
	c = 0
	while True:
		if l == []:
			break
		p = s
		s = 0
		for i in range(p):
			if l == []:
				break
			s = s + l.pop()
		ans += 1
	print(ans)


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	a = [int(_) for _ in input().strip().split()]
	m = 1
	i = 1
	h = 0
	while i < n:
		j = i + 1
		cur = 0
		while j < n:
			if a[j - 1] > a[j]:
				cur += 1
			if cur == m:
				break
			j += 1
		m = j - i
		i = j
		h += 1
	print(h)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	n = get_int()
	ls = get_list()
	if n == 2:
		print(1)
		return
	depth = 2
	no_of_par = 1
	no_of_new_par = 0
	i = 0
	start = 2
	while start < n and ls[start] > ls[start - 1]:
		start += 1
		no_of_par += 1
	if start == n:
		print(1)
		return
	for j in range(start, n):
		no_of_new_par += 1
		if ls[j] < ls[j - 1]:
			i += 1
			if i > no_of_par:
				no_of_par = no_of_new_par - 1
				no_of_new_par = 1
				i = 1
				depth += 1
	print(depth)

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


import sys, math
input = sys.stdin.readline
from collections import deque
t = int(input())
for r in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	q = deque()
	ans = 1
	current = 1
	currentHeight = 1
	for i in range(1, n):
		if l[i] > current:
			q.append([l[i], currentHeight])
			current = l[i]
		else:
			newCurrent = q.popleft()
			q.append([l[i], newCurrent[1] + 1])
			current = l[i]
			currentHeight = newCurrent[1] + 1
			ans = newCurrent[1] + 1
	print(ans)


def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		a = lin()[1:] + [0]
		if n < 3:
			print(n - 1)
			continue
		sol = 0
		ch = 0
		ch1 = []
		ch2 = 1
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				ch += 1
				ch1.append(ch2)
				ch2 = 1
			else:
				ch2 += 1
		nx_lf = 0
		pv_lf = 1
		ch = 0
		for val in ch1:
			nx_lf += val
			if pv_lf > 1:
				ch = 1
				pv_lf -= 1
			else:
				ch = 0
				sol += 1
				(pv_lf, nx_lf) = (nx_lf, 0)
		print(sol + ch)
main()


from queue import Queue
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = input().split()
	for i in range(n):
		a[i] = int(a[i])
	q = Queue()
	depth = {1: 0}
	ans = 0
	bap = 1
	for i in range(1, n):
		depth[a[i]] = depth[bap] + 1
		ans = max(ans, depth[a[i]])
		q.put(a[i])
		if i + 1 < n and a[i] > a[i + 1]:
			bap = q.get()
	print(ans)


from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for tt in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	levels = [1]
	(last_num, node_chunk, height) = (-inf, 0, 0)
	for i in range(1, N):
		v = arr[i]
		if v < last_num:
			node_chunk += 1
			if node_chunk == levels[height]:
				height += 1
				node_chunk = 0
		if height + 1 >= len(levels):
			levels.append(0)
		levels[height + 1] += 1
		last_num = v
	print(len(levels) - 1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	level = 0
	p = 0
	ans = 1
	for i in range(1, n):
		if l[i] > l[i - 1]:
			p += 1
		elif level == 0:
			ans += 1
			level = p - 1
		else:
			level -= 1
	print(ans)


from sys import stdin, stdout
t = int(stdin.readline())
for k in range(t):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	depth = 1
	prevskips = 0
	nextskips = 0
	maxtillnow = 1
	for i in range(1, n):
		if arr[i] > maxtillnow:
			maxtillnow = arr[i]
			nextskips += 1
		else:
			if prevskips > 1:
				prevskips -= 1
				nextskips += 1
			else:
				prevskips = nextskips
				depth += 1
				nextskips = 1
			maxtillnow = arr[i]
	print(depth)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import bisect
from collections import Counter
import bisect
from heapq import *
from collections import defaultdict, deque

def okay(x, y):
	if x < 0 or x >= 3:
		return False
	if y < n and mat[x][y] != '.':
		return False
	if y + 1 < n and mat[x][y + 1] != '.':
		return False
	if y + 2 < n and mat[x][y + 2] != '.':
		return False
	return True
for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	ans = 1
	node = [0] * n
	node[0] = -1
	var = 0
	for i in range(1, n):
		if ls[i] > ls[i - 1]:
			continue
		elif node[var] == -1:
			ans += 1
			var += 1
			node[i - 1] = -1
		else:
			var += 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	(mxdep, dep) = (1, 1)
	q = []
	for i in range(1, n):
		if a[i] > a[i - 1]:
			q.append((a[i], dep))
		else:
			(_, d) = q.pop(0)
			dep = d + 1
			q.append((a[i], dep))
		mxdep = max(dep, mxdep)
	print(mxdep)


a = int(input())
for i in range(a):
	b = int(input())
	arr = list(map(int, input().split()))
	sarr = []
	tans = 1
	for i in range(2, len(arr)):
		if arr[i] >= arr[i - 1]:
			tans = tans + 1
		else:
			sarr.append(tans)
			tans = 1
	sarr.append(tans)
	elem = 0
	pelem = 1
	sett = 0
	ans = 0
	for i in range(0, len(sarr)):
		sett = sett + 1
		elem = elem + sarr[i]
		if sett == pelem:
			ans = ans + 1
			pelem = elem
			elem = 0
			sett = 0
	if not elem == 0:
		ans = ans + 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	(increase, inc) = ([1], 0)
	for i in range(1, n):
		if l[i] > l[i - 1]:
			inc += 1
		else:
			increase.append(max(1, inc))
			inc = 1
	increase.append(max(1, inc))
	(depth, tmp) = (0, 1)
	i = 1
	while i < len(increase):
		count = 0
		while tmp > 0:
			count += increase[i]
			tmp -= 1
			i += 1
			if i >= len(increase):
				depth += 1
				break
		depth += 1
		tmp = count
	print(depth - 1)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ans = 1
	cnt_old = 1
	cnt = 1
	for (a1, a2) in zip(A[1:], A[2:]):
		if a1 < a2:
			cnt_old += 1
		else:
			cnt -= 1
			if cnt == 0:
				ans += 1
				cnt = cnt_old
	print(ans)


import sys
from math import ceil, factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(int(input())):
	n = int(input())
	A = rl()
	ans = 1
	weight = 1
	now_weight = 1
	for i in range(2, n):
		if A[i - 1] < A[i]:
			weight += 1
			now_weight += 1
		else:
			now_weight += 1
			if now_weight > weight:
				ans += 1
				now_weight = 1
	print(ans)


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	n = len(a)
	have = [1]
	c = 1
	for i in range(2, n):
		if a[i] < a[i - 1]:
			have.append(c)
			c = 0
		c += 1
	have.append(c)
	height = 0
	cur = 0
	child = have[cur]
	total = 0
	while total < n:
		height += 1
		here = have[cur]
		c = 1
		cur += 1
		while cur < len(have) and c < child:
			here += have[cur]
			cur += 1
			c += 1
		child = here
		total += child
	print(height - 1)


from collections import deque

def solve(n, a):
	ans = 0
	cnt = 1
	queue = deque()
	queue.append(1)
	idx = 1
	x = 0
	while queue:
		x = 0
		for i in range(cnt):
			temp = queue.popleft()
			prev = -1
			while idx < n:
				if a[idx] < prev:
					break
				prev = a[idx]
				queue.append(a[idx])
				x += 1
				idx += 1
		cnt = x
		if queue:
			ans += 1
	return ans
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))
	t -= 1


t = int(input())
for z in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	d = a.pop(0)
	l = len(a)
	m = 0
	vis = 1
	k = 0
	k_next = 0
	for i in range(l):
		n = a[i]
		if n >= m:
			k_next += 1
			m = n
		elif k:
			k -= 1
			k_next += 1
			m = n
		else:
			vis += 1
			m = n
			k = k_next - 1
			k_next = 1
	print(vis)


def solve(arr, n, ans):
	arr.pop(0)
	depth = 1
	prev_level_nodes = 1
	next_level_nodes = 0
	kids = 0
	prev = 0
	count = 0
	for i in arr:
		if i > prev:
			kids += 1
		else:
			if prev_level_nodes > 0:
				prev_level_nodes -= 1
			if prev_level_nodes == 0:
				depth += 1
				prev_level_nodes = next_level_nodes
				kids = 1
				next_level_nodes = 0
		next_level_nodes += 1
		prev = i
	ans.append(str(depth))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	print('\n'.join(ans))
main()


import sys
import math
input = sys.stdin.readline

def get_int():
	return int(input().strip())

def get_int_list():
	return list(map(int, input().strip().split()))

def get_char_list():
	return list(input().strip())
cases = get_int()
for _ in range(cases):
	n = get_int()
	ints = get_int_list()
	result = 1
	ele = 1
	cele = 1
	for i in range(2, n):
		if ints[i] < ints[i - 1]:
			ele -= 1
		if ele == 0:
			result += 1
			ele = cele
			cele = 1
		else:
			cele += 1
	print(result)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	(pre, new) = (1, 0)
	i = 1
	ct = 1
	temp = 0
	while i < n - 1:
		if arr[i] > arr[i + 1]:
			temp += 1
			pre -= 1
			if pre > 0:
				new += temp
			else:
				pre = new + temp
				new = 0
				ct += 1
			temp = 0
		else:
			temp += 1
		i += 1
	print(ct)


import collections
for t in range(int(input())):
	n = int(input())
	nums = collections.deque(map(int, input().split()))
	out = 0
	stack = [nums.popleft()]
	while nums:
		temp = []
		while stack and nums:
			stack.pop()
			val = nums.popleft()
			temp.append(val)
			while nums and val <= nums[0]:
				val = nums.popleft()
				temp.append(val)
		out += 1
		stack = temp
	print(out)


import math
from collections import deque
from sys import stdin, stdout, setrecursionlimit
from string import ascii_letters
letters = ascii_letters[:26]
from collections import defaultdict
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	last = 0
	ln = 0
	res = []
	level = [1]
	for i in arr:
		if i == 1:
			continue
		if i < last:
			if ln > 0:
				res.append(ln)
			ln = 1
		else:
			ln += 1
		last = i
	res.append(ln)
	nlevel = []
	cnt = 0
	ind = 0
	for i in res:
		if ind < len(level) and level[ind] == 0:
			ind += 1
		if ind >= len(level):
			level = nlevel[:]
			nlevel = []
			ind = 0
			cnt += 1
		level[ind] -= 1
		nlevel.append(i)
	print(cnt + 1)


import sys
input = sys.stdin.buffer.readline
q = int(input())
INF = 10 ** 9
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split())) + [-1]
	res = [1]
	cnt = 1
	for i in range(1, n):
		if a[i] < a[i + 1]:
			cnt += 1
		else:
			res.append(cnt)
			cnt = 1
	idx = 0
	pars = 1
	ans = -1
	while True:
		if idx >= len(res):
			break
		val = 0
		for i in range(idx, idx + pars):
			if i < len(res):
				val += res[i]
			else:
				break
		idx = idx + pars
		pars = val
		ans += 1
	print(ans)


from collections import deque

def solve():
	n = int(input())
	a = deque(list(map(int, input().split())))
	ans = 0
	nodes = 0
	mother_repository = 1
	repository = 0
	now = 10 ** 6
	a.popleft()
	while a:
		nodes += 1
		x = a.popleft()
		if now > x:
			now = x
			if mother_repository > 1:
				repository += nodes
				mother_repository -= 1
				nodes = 0
				continue
			elif mother_repository == 1:
				repository += nodes
				ans += 1
				mother_repository = repository
				repository = 0
				nodes = 0
				continue
		else:
			now = x
	print(ans)
	return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	if n > 1:
		a = 1
		b = 1
		lis = []
		for j in range(1, n - 1):
			if arr[j + 1] < arr[j]:
				lis.append(a)
				b += 1
				a = 1
			else:
				a += 1
		lis.append(a)
		num = lis[0]
		ans += 1
		j = 1
		while j < b:
			temp = 0
			l = j
			for k in range(l, min(l + num, b)):
				temp += lis[k]
				j += 1
			num = temp
			ans += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7
t = int(input())
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve(n, l):
	parent = 0
	d = {}
	for i in range(1, n):
		if l[i] < l[i - 1] and i - 1 > 0:
			parent += 1
		d[i] = d.get(parent, 0) + 1
	return d[n - 1]
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(solve(n, l))


for ttt in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = [10 ** 9] * n
	res[0] = 0
	l = 0
	for i in range(1, n):
		if i - 1 > 0 and arr[i - 1] > arr[i]:
			l += 1
		res[i] = res[l] + 1
	print(res[n - 1])


import math
from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd
import bisect
import sys
import random
import heapq

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
for _ in range(int(input())):
	n = int(input())
	arr = deque(get_array())
	queue = deque([arr.popleft()])
	ht = [0] * n
	while queue and arr:
		k = queue.popleft()
		cur = arr.popleft()
		queue.append(cur)
		ht[cur - 1] = ht[k - 1] + 1
		while arr and cur < arr[0]:
			cur = arr.popleft()
			queue.append(cur)
			ht[cur - 1] = ht[k - 1] + 1
	print(max(ht))


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	lis = [[1]]
	now = []
	tmp = 0
	for i in range(1, n):
		if len(now) == 0:
			now.append(a[i])
			tmp = 1
		elif now[-1] > a[i]:
			if tmp == len(lis[-1]):
				lis.append(now)
				now = [a[i]]
				tmp = 1
			else:
				tmp += 1
				now.append(a[i])
		else:
			now.append(a[i])
	if len(now) > 0:
		lis.append(now)
	print(len(lis) - 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = N()
	a = RLL()
	d = [1]
	now = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			d.append(now)
			now = 1
		else:
			now += 1
	d.append(now)
	t = 1
	(l, k) = (2, d[1])
	while l < len(d):
		t += 1
		p = sum(d[l:l + k])
		l += k
		k = p
	print(t)


C = int(input())
for i in range(C):
	SIZE = int(input())
	L = list(map(int, input().split()))
	HEIGHT = prev = curr = 1
	for j in range(2, SIZE):
		if L[j - 1] < L[j]:
			prev += 1
		else:
			curr -= 1
			if curr == 0:
				HEIGHT += 1
				curr = prev
				prev = 0
			prev += 1
	print(HEIGHT)


def solve(n, a):
	ret = 1
	prev_cnt = 1
	tmp = 1
	cnt = 1
	for i in range(2, n):
		if a[i - 1] > a[i]:
			if tmp < prev_cnt:
				tmp += 1
				cnt += 1
			else:
				ret += 1
				prev_cnt = cnt
				tmp = 1
				cnt = 1
		else:
			cnt += 1
	return ret
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


def bfs(arr, n):
	Current = 1
	(nxt, d) = (0, 0)
	index = 1
	while Current > 0 and index < n:
		Current -= 1
		Count = 0
		while index < n:
			if arr[index] < arr[index - 1] and Count != 0:
				break
			else:
				nxt += 1
				index += 1
				Count += 1
		if index == n:
			return d + 1
		if Current == 0:
			if nxt > 0:
				d += 1
			Current = nxt
			nxt = 0
	return d
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(bfs(arr, n))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	height = 1
	last = 1
	x = 1
	tmp = 0
	while x < n:
		if arr[x] < arr[x - 1]:
			last -= 1
		if last == 0:
			height += 1
			last = tmp
			tmp = 1
		else:
			tmp += 1
		x += 1
	print(height)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [10 ** 9] * n
	ans[0] = 0
	last = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			last += 1
		ans[i] = ans[last] + 1
	print(ans[-1])


T = int(input())
for _ in range(0, T):
	n = int(input())
	s = [int(x) for x in input().split()]
	c = 1
	L = []
	for i in range(2, len(s)):
		if s[i] > s[i - 1]:
			c += 1
		else:
			L.append(c)
			c = 1
	L.append(c)
	ans = 0
	c = 1
	ptr = 0
	while ptr < len(L):
		k = 0
		for i in range(ptr, min(ptr + c, len(L))):
			k += L[i]
		ans += 1
		ptr = min(ptr + c, len(L))
		c = k
	print(ans)


for _ in range(int(input())):
	n = int(input()) - 1
	arr = list(map(int, input().split()))[1:] + [-1]
	ar2 = []
	prev = -1
	curr = 0
	for e in arr:
		if e > prev:
			curr += 1
		else:
			ar2.append(curr)
			curr = 1
		prev = e
	h = 1
	ptr = 1
	s = ar2[0]
	while ptr < len(ar2):
		(ptr, s) = (ptr + s, sum(ar2[ptr:ptr + s]))
		h += 1
	print(h)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	h = 0
	prev = 10000000000.0
	q = [(10000000000.0, 0)]
	a[0] = 10000000000.0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			(x, h) = q.pop(0)
			q.append((a[i], h + 1))
		else:
			q.append((a[i], q[-1][1]))
	print(q[-1][1])


t = int(input())
while t:
	n = int(input())
	s = list(map(int, input().split()))
	height = 1
	prvl = 1
	level = 0
	for i in range(1, len(s) - 1):
		level += 1
		if s[i] > s[i + 1]:
			prvl -= 1
		if prvl == 0:
			height += 1
			prvl = level
			level = 0
	print(height)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	psize = 1
	csize = 0
	h = 0
	i = 1
	q = []
	q.append(a[0])
	while len(q) != 0:
		s = len(q)
		for p in range(s):
			del q[0]
			if i < n:
				q.append(a[i])
				i += 1
			while i < n and a[i] > a[i - 1]:
				q.append(a[i])
				i += 1
		if i == n:
			break
		h += 1
	print(h + 1)


from sys import stdin
rl = stdin.readline

def main(n, a):
	(depth, start_i, end_i, members) = (0, 0, 0, 1)
	for i in range(1, n):
		if a[i] < a[i - 1]:
			members -= 1
			if members == 0:
				depth += 1
				start_i = end_i + 1
				members = i - start_i
				end_i = i - 1
	print(depth + 1)
t = int(rl())
cases = [(int(rl()), list(map(int, rl().split()))) for _ in range(t)]
for (n, a) in cases:
	main(n, a)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	h = [0] * n
	h[0] = 0
	lst = 0
	for i in range(1, n):
		if i - 1 > 0 and arr[i - 1] > arr[i]:
			lst += 1
		h[i] = h[lst] + 1
	print(h[n - 1])


def soluciona():
	n = int(input())
	visitados = list(map(int, input().split()))
	anterior = 0
	largura = 1
	nova_largura = 0
	altura = 1
	for v in visitados[1:]:
		if anterior > v:
			largura -= 1
		if largura == 0:
			largura = nova_largura
			nova_largura = 0
			altura += 1
		nova_largura += 1
		anterior = v
	print(altura)
for _ in range(int(input())):
	soluciona()


from collections import defaultdict
from queue import PriorityQueue, Queue
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	q = Queue()
	level = [0] * (n + 1)
	q.put(1)
	i = 1
	while i < n:
		x = q.get()
		j = i + 1
		q.put(a[i])
		level[a[i]] = level[x] + 1
		while j < n and a[j] > a[j - 1]:
			level[a[j]] = level[x] + 1
			q.put(a[j])
			j += 1
		i = j
	print(max(level))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import deque
for j in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	seg = [1]
	for s in range(2, n):
		if vals[s] >= vals[s - 1]:
			seg[-1] += 1
		else:
			seg.append(1)
	height = 0
	queue = deque([1, 0])
	for s in range(len(seg)):
		if queue[-1] == 0:
			height += 1
		queue[-1] += seg[s]
		queue[0] -= 1
		if queue[0] == 0:
			queue.popleft()
			queue.append(0)
	print(height)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	level = 0
	par = 1
	i = 1
	while i < len(arr):
		tempPar = 0
		while i < len(arr) and par:
			prev = arr[i]
			i += 1
			temp = 1
			while i < len(arr) and arr[i] >= prev:
				prev = arr[i]
				i += 1
				temp += 1
			par -= 1
			tempPar += temp
		par = tempPar
		level += 1
	print(level)


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	bx = X[1]
	h = 1
	c = 1
	bc = 1
	xx = 0
	for x in X[2:]:
		if x < bx:
			xx += 1
		if bc <= xx:
			h += 1
			bc = c
			c = 1
			xx = 0
		else:
			c += 1
		bx = x
	print(h)


t = int(input())
for i in range(t):
	n = int(input())
	(current_parent, last_children, *nodes) = list(map(int, input().split()))
	max_height = 1
	current_height = 1
	parents = [(last_children, 2)]
	for node in nodes:
		if node < last_children:
			(current_parent, current_height) = parents.pop(0)
			if current_height > max_height:
				max_height = current_height
		last_children = node
		parents.append((node, current_height + 1))
	print(max_height)


import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = [0] * T
for t in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	num = 1
	lis = []
	for i in range(2, n):
		if A[i] > A[i - 1]:
			num += 1
		else:
			lis.append(num)
			num = 1
	lis.append(num)
	cnt = 1
	lis = lis[::-1]
	while len(lis):
		ans[t] += 1
		new = 0
		for i in range(min(cnt, len(lis))):
			new += lis.pop()
		cnt = new
print(*ans, sep='\n')


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	N = INT()
	A = LIST()
	A.reverse()
	A.pop()
	depth = 0
	parcnt = 1
	while A and parcnt:
		nxt = 0
		for _ in range(parcnt):
			ch = -1
			while A and ch < A[-1]:
				ch = A.pop()
				nxt += 1
		parcnt = nxt
		depth += 1
	print(depth)


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

def solve():
	n = itg()
	arr = list(mpint())[1:]
	prev = 0
	curr = ans = 1
	mx = arr.pop(0)
	for a in arr:
		if mx < a:
			curr += 1
		elif prev:
			prev -= 1
			curr += 1
		else:
			ans += 1
			prev = curr - 1
			curr = 1
		mx = a
	return ans

def main():
	for _ in range(itg()):
		print(solve())
DEBUG = 0
URL = 'https://codeforces.com/contest/1437/problem/D'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
elif DEBUG == 2:
	main()
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	main()


import sys
from collections import deque
sys.setrecursionlimit(10 ** 9)
from copy import deepcopy

def maxH(curr, adjacent_arr):
	global memo
	if curr in memo:
		return memo[curr]
	adjacent_nodes = adjacent_arr[curr]
	ans = -float('inf')
	if len(adjacent_nodes) == 0:
		return 0
	for node in adjacent_nodes:
		curr_ans = 1 + maxH(node, adjacent_arr)
		ans = max(ans, curr_ans)
	memo[curr] = ans
	return ans
t = int(input())
for test in range(t):
	n = int(input())
	bfs = list(map(int, input().strip().split()))
	adjacent_arr = [[] for i in range(n + 1)]
	prev = [bfs[0], 0]
	root = [bfs[0], 0]
	n = len(bfs)
	memo = {}
	queue = deque()
	level = 0
	max_level = 0
	for i in range(1, n):
		if bfs[i] > prev[0]:
			adjacent_arr[root[0]].append(bfs[i])
			curr_prev = [bfs[i], root[1] + 1]
			prev = deepcopy(curr_prev)
			max_level = max(prev[1], max_level)
			queue.append(curr_prev)
		else:
			root = queue.popleft()
			adjacent_arr[root[0]].append(bfs[i])
			curr_prev = [bfs[i], root[1] + 1]
			prev = deepcopy(curr_prev)
			queue.append(curr_prev)
			max_level = max(prev[1], max_level)
	print(max_level)


import math, sys
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

def In():
	return map(int, sys.stdin.readline().split())

def Sn():
	return sys.stdin.readline().strip()

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		ans = 1
		last = 1
		p = 1
		for i in range(2, n):
			if l[i] > l[i - 1]:
				last += 1
				p += 1
			else:
				p += 1
				if p > last:
					ans += 1
					p = 1
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import sys
from math import gcd, sqrt, ceil, log2
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
import math
sys.setrecursionlimit(2 * 10 ** 5 + 10)
import heapq
from itertools import permutations
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_sum(bit, i):
	s = 0
	i += 1
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def update(bit, n, i, v):
	i += 1
	while i <= n:
		bit[i] += v
		i += i & -i

def modInverse(b, m):
	g = math.gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def primeFactors(n):
	sa = set()
	sa.add(n)
	while n % 2 == 0:
		sa.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			sa.add(i)
			n = n // i
	return sa

def seive(n):
	pri = [True] * (n + 1)
	p = 2
	while p * p <= n:
		if pri[p] == True:
			for i in range(p * p, n + 1, p):
				pri[i] = False
		p += 1
	return pri

def check_prim(n):
	if n < 0:
		return False
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def getZarr(string, z):
	n = len(string)
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1

def search(text, pattern):
	concat = pattern + '$' + text
	l = len(concat)
	z = [0] * l
	getZarr(concat, z)
	ha = []
	for i in range(l):
		if z[i] == len(pattern):
			ha.append(i - len(pattern) - 1)
	return ha

def mergeIntervals(arr):
	arr.sort(key=lambda x: x[0])
	m = []
	s = -10000
	max = -100000
	for i in range(len(arr)):
		a = arr[i]
		if a[0] > max:
			if i != 0:
				m.append([s, max])
			max = a[1]
			s = a[0]
		elif a[1] >= max:
			max = a[1]
	if max != -100000 and [s, max] not in m:
		m.append([s, max])
	return m

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	if n == 1:
		print(0)
	else:
		i = 1
		ans = 0
		level = defaultdict(int)
		now = [l[0]]
		while i < n:
			z = now.pop(0)
			yo = []
			while i < n - 1 and l[i] < l[i + 1]:
				yo.append(l[i])
				i += 1
			yo.append(l[i])
			for j in yo:
				level[j] = level[z] + 1
			now += yo
			i += 1
		for i in level:
			ans = max(ans, level[i])
		print(ans)


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	lvl = [1] + [0] * (n - 1)
	curlv = 1
	cnt = 0
	for i in range(1, n):
		if s[i] > s[i - 1]:
			lvl[curlv] += 1
		else:
			cnt += 1
			if cnt >= lvl[curlv - 1]:
				cnt = 0
				curlv += 1
				lvl[curlv] = 1
			else:
				lvl[curlv] += 1
	print(curlv)


from sys import stdin, stdout
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	h = 0
	s = arr[1]
	count = 1
	idk = 0
	for i in arr[1:]:
		if i < s:
			s = i
			count -= 1
			if count == 0:
				h += 1
				count = idk
				idk = 1
			else:
				idk += 1
		else:
			s = i
			idk += 1
	print(h + 1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	v = list(map(int, input().split()))
	height = 1
	stack = []
	inv = 0
	size = 0
	goal = 1
	for i in range(1, n - 1):
		if v[i] > v[i + 1]:
			inv += 1
		size += 1
		if inv == goal:
			height += 1
			goal = size
			size = 0
			inv = 0
	print(height)


import sys
import collections
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	if len(A) <= 1:
		print(0)
	cnt = collections.deque()
	A = A[1:]
	pre = 0
	for i in range(1, len(A)):
		if A[i] < A[i - 1]:
			cnt.append(i - pre)
			pre = i
	cnt.append(len(A) - pre)
	stack = [-1]
	ans = 0
	num = 1
	while cnt:
		nn = 0
		ans += 1
		for _ in range(num):
			if cnt:
				nn += cnt.popleft()
			else:
				break
		num = nn
	print(ans)


from collections import deque
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	g = [[] for i in range(n + 1)]
	d = deque([1])
	prev = 1
	i = 1
	while d:
		p = d.popleft()
		if i >= n:
			break
		g[p].append(a[i])
		prev = a[i]
		i += 1
		d.append(prev)
		while i < n:
			if i < n and a[i] > prev:
				d.append(a[i])
				prev = a[i]
				g[p].append(a[i])
				i += 1
			else:
				break
	h = [0] * (n + 1)
	d = deque([1])
	while d:
		p = d.popleft()
		for k in g[p]:
			h[k] = h[p] + 1
			d.append(k)
	print(max(h))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	i = 1
	ncur = 1
	sum = 0
	while i < n:
		ans += 1
		for _ in range(0, ncur):
			sum += 1
			while i + 1 < n and a[i + 1] > a[i]:
				sum += 1
				i += 1
			i += 1
			if i >= n:
				break
		ncur = sum
		sum = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()] + [-1]
	levels = [[1]]
	pointer = 0
	floor = [a[1]]
	ind = 1
	candidates = []
	for (ind, a_i) in enumerate(a[1:]):
		if a[ind] > a_i:
			candidates.append(floor)
			floor = [a_i]
		elif ind != 0:
			floor.append(a_i)
	for candidate in candidates:
		levels[pointer].pop()
		if len(levels) == pointer + 1:
			levels.append(candidate)
		else:
			levels[pointer + 1].extend(candidate)
		if len(levels[pointer]) == 0:
			pointer += 1
	print(len(levels) - 1)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')

def addEdge(a, b):
	graph[a].append(b)
	graph[b].append(a)

def Bfs(src, dest=-1):
	visited = dd(bool)
	dist = dd(int)
	q = deque([])
	q.append(src)
	visited[src] = True
	dist[src] = 0
	while q:
		node = q.popleft()
		for neighbour in graph[node]:
			if not visited[neighbour]:
				q.append(neighbour)
				visited[neighbour] = True
				dist[neighbour] = dist[node] + 1
	return max(list(dist.values()))
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	pt = 0
	stack = []
	graph = [[] for i in range(n + 1)]
	for i in range(1, n):
		if len(stack) == 0:
			stack.append(arr[i])
			addEdge(arr[pt], arr[i])
		else:
			ele = arr[i]
			if ele < stack[-1]:
				stack = [ele]
				pt += 1
				addEdge(arr[pt], arr[i])
			else:
				stack.append(ele)
				addEdge(arr[pt], arr[i])
	ans = Bfs(1)
	out(ans)


from sys import stdin, stdout
from collections import *
from math import *
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')
ANS = []

def solve():
	n = inp()
	l = li()
	i = 0
	j = 1
	d = {i: [] for i in range(n)}
	while i < n:
		if j == n:
			break
		d[i].append(j)
		a = l[j]
		j += 1
		while j < n and l[j] >= a:
			d[i].append(j)
			a = l[j]
			j += 1
		i += 1
	level = {}
	level[0] = 0
	q = deque()
	q.append((0, 0))
	ans = 0
	visited = [False for i in range(n)]
	while q:
		(a, b) = q.popleft()
		for i in d[a]:
			if not visited[i]:
				visited[i] = True
				level[i] = b + 1
				q.append((i, level[i]))
				ans = max(ans, level[i])
	pr(ans)
for _ in range(inp()):
	solve()


import math
from collections import Counter, defaultdict, deque

def f(n, p):
	height = 0
	q = []
	i = 1
	l = 1
	cl = 0
	while i < n:
		if q == []:
			q.append(p[i])
			cl += 1
			i += 1
			continue
		if p[i] > q[-1]:
			q.append(p[i])
			cl += 1
			i += 1
		else:
			l -= 1
			if l > 0:
				q = []
			else:
				l = cl
				height += 1
				cl = 0
				q = []
	if q != [] and l > 0:
		height += 1
	return height
t = int(input())
result = []
for i in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	result.append(f(n, p))
for i in range(t):
	print(result[i])


import math
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	prev = -1
	count = 0
	flag = 0
	limit = 0
	cur = 1
	le = 0
	for i in range(1, n):
		if arr[i] >= prev:
			le += 1
		else:
			limit += 1
			if limit >= cur:
				count += 1
				cur = le
				le = 1
				limit = 0
			else:
				le += 1
		prev = arr[i]
	count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	increasingGpSizes = [1]
	a.append(-1)
	prev = -1
	sz = 0
	for i in range(1, n + 1):
		if a[i] >= prev:
			sz += 1
		else:
			increasingGpSizes.append(sz)
			sz = 1
		prev = a[i]
	depths = []
	curr = []
	for x in increasingGpSizes:
		if len(depths) == 0:
			depths.append([1])
			curr = []
		else:
			curr.append(x)
			if len(curr) == sum(depths[-1]):
				depths.append(curr)
				curr = []
	if len(curr) > 0:
		depths.append(curr)
	print(len(depths) - 1)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	cur = 0
	prev = res = 1
	for i in range(1, n):
		if a[i] > a[i - 1]:
			cur += 1
		else:
			prev -= 1
			if prev > 0:
				cur += 1
			else:
				res += 1
				prev = cur
				cur = 1
	print(res)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = inar()
		ans = 0
		temp = 0
		old = 1
		new = 0
		counter = 0
		for i in range(1, n):
			if i == 1:
				temp = 1
				continue
			if arr[i] > arr[i - 1]:
				temp += 1
			else:
				if counter == 0:
					ans += 1
				counter = 1
				new += temp
				temp = 1
				old -= 1
				if old == 0:
					old = new
					new = 0
					counter = 0
		if counter == 0:
			ans += 1
		print(ans)
main()


tests = int(input())
for test in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	res = 1
	tails = 1
	ntails = 0
	i = 1
	while i < n:
		if tails == 0:
			res += 1
			tails = ntails
			ntails = 0
		while i + 1 < n and a[i] < a[i + 1]:
			i += 1
			ntails += 1
		i += 1
		ntails += 1
		tails -= 1
	print(res)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	a = inpl()
	pre = a[1]
	res = 1
	cnt = 1
	rem = 1
	for i in range(2, n):
		if pre > a[i]:
			rem -= 1
			if rem == 0:
				rem = cnt
				res += 1
		else:
			cnt += 1
		pre = a[i]
	print(res)


import typing
import sys
import math
import collections
import bisect
import itertools
import heapq
import decimal
INF = 10 ** 20
MOD = 10 ** 9 + 7

def ni():
	return int(sys.stdin.buffer.readline())

def na():
	return list(map(int, sys.stdin.buffer.readline().split()))

def na1():
	return list(map(lambda x: int(x) - 1, sys.stdin.buffer.readline().split()))

def main():
	t = ni()
	for _ in range(t):
		n = ni()
		a = na()
		ans = 1
		child = []
		prevcapacity = 1
		nxtcapacity = 0
		i = 1
		while i < n:
			if len(child) == 0:
				child.append(a[i])
				i += 1
				continue
			if a[i] > child[-1]:
				child.append(a[i])
				i += 1
			else:
				prevcapacity -= 1
				nxtcapacity += len(child)
				child = []
				if prevcapacity == 0:
					ans += 1
					prevcapacity = nxtcapacity
					nxtcapacity = 0
		print(ans)
main()


import sys, math, itertools, collections, copy
input = sys.stdin.readline

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	if n <= 2:
		print(1)
		return
	(ans, that_lvl_nodes, prev_lvl_nodes, cur_blocks_nodes) = (1, 0, 1, 0)
	for i in range(2, n):
		if a[i] < a[i - 1]:
			if cur_blocks_nodes + 1 >= prev_lvl_nodes:
				prev_lvl_nodes = that_lvl_nodes + 1
				that_lvl_nodes = 0
				cur_blocks_nodes = 0
				ans += 1
			else:
				cur_blocks_nodes += 1
				that_lvl_nodes += 1
		else:
			that_lvl_nodes += 1
	print(ans)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = 1
	cnt = 1
	mp = {}
	for i in range(n + 1):
		mp[i] = 0
	mp[1] = 1
	for i in range(2, n):
		if ar[i] < ar[i - 1]:
			if mp[cnt - 1] >= 1:
				mp[cnt] = mp[cnt] + 1
				mp[cnt - 1] -= 1
			else:
				ans += 1
				cnt += 1
				mp[cnt] += 1
				mp[cnt - 1] -= 1
		else:
			mp[cnt] += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	parent = 1
	level = 1
	child = 1
	curr = a[1]
	for i in range(2, n):
		if a[i] > curr:
			child += 1
			curr = a[i]
		else:
			parent -= 1
			if parent > 0:
				child += 1
				curr = a[i]
			else:
				level += 1
				parent = child
				child = 1
				curr = a[i]
	print(level)


import os, sys
from collections import defaultdict, Counter, deque
from io import BytesIO, IOBase
from math import gcd, inf

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		ans = 0
		if n > 1:
			a = 1
			b = 1
			lis = []
			for j in range(1, n - 1):
				if arr[j + 1] < arr[j]:
					lis.append(a)
					b += 1
					a = 1
				else:
					a += 1
			lis.append(a)
			num = lis[0]
			ans += 1
			j = 1
			while j < b:
				temp = 0
				l = j
				for k in range(l, min(l + num, b)):
					temp += lis[k]
					j += 1
				num = temp
				ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(inp())
	a = lis()
	ans = 0
	deq = deque([])
	for i in range(n):
		deq.append(a[i])
	par = deq.popleft()
	prevcnt = 1
	cnt = 0
	prev = 0
	while len(deq) != 0:
		new = deq.popleft()
		if prev == 0:
			prev = new
			cnt += 1
			ans += 1
		elif new > prev:
			prev = new
			cnt += 1
		elif prevcnt > 1:
			prevcnt -= 1
			prev = new
			cnt += 1
		else:
			prevcnt = cnt
			cnt = 1
			par = prev
			prev = new
			ans += 1
	if prev == 0:
		ans += 1
	print(ans)
testcase(int(inp()))


nTests = int(input())
for test in range(nTests):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print('0')
	else:
		n1 = 1
		n2 = 0
		ret = 1
		last = a[0]
		for i in range(1, n):
			if a[i] < last:
				n1 -= 1
				if n1 == 0:
					ret += 1
					n1 = n2
			else:
				n2 += 1
			last = a[i]
		print(ret)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	n = val()
	l = li()
	lastelement = depth = 0
	itr = parents = maxelements = curr = 1
	while itr < n:
		currelements = 0
		while parents:
			lastelement = -1
			while itr < n and l[itr] > lastelement:
				lastelement = l[itr]
				itr += 1
				currelements += 1
			parents -= 1
		parents = currelements
		depth += 1
	print(depth)


from math import *
import threading
import sys
mod = 10 ** 9 + 7

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li
sys.setrecursionlimit(300000)
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	last_height = 0
	height = [0]
	for i in range(1, n):
		if i > 1:
			if a[i] < a[i - 1]:
				last_height += 1
		height.append(height[last_height] + 1)
	print(height[-1])


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	prev = 1
	curr = 0
	ans = 0
	ok = 0
	for i in range(1, n):
		if li[i] > li[i - 1]:
			ok += 1
			continue
		curr += 1
		if prev == curr:
			prev = ok
			ok = 1
			curr = 0
			ans += 1
		else:
			ok += 1
	print(ans + 1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 1
	c = {0: 1, 1: 0}
	k = 0
	pre = 1
	for i in range(1, n):
		if a[i] > pre:
			pre = a[i]
			k += 1
		elif c[ans - 1] <= 1:
			if ans in c:
				c[ans] += k
			else:
				c[ans] = k
			ans += 1
			pre = a[i]
			k = 1
		else:
			c[ans - 1] -= 1
			if ans in c:
				c[ans] += k
			else:
				c[ans] = k
			k = 1
			pre = a[i]
	print(ans)


def solve(n, arr):
	height = 1
	prev = 1
	now = 0
	for i in range(1, n):
		if arr[i] > arr[i - 1]:
			now += 1
		else:
			prev -= 1
			if prev == 0:
				prev = now
				height += 1
				now = 1
			else:
				now += 1
	return height
T = int(input())
for t in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = solve(n, arr)
	print(ans)


for _ in range(int(input())):
	num_children = int(input())
	children = list(map(int, input().split()))
	branches = 1
	next_branches = 1
	layer = 1
	previous = children[1]
	for child in children[2:]:
		if child < previous:
			branches -= 1
			if branches == 0:
				layer += 1
				branches = next_branches
				next_branches = 0
		next_branches += 1
		previous = child
	print(layer)


t = int(input())
for _ in range(0, t):
	n = int(input())
	ls = list(map(int, input().split()))
	count = 1
	f = 0
	ch = 0
	level = [0] * 200000
	index = 0
	for i in range(1, n):
		if ls[i - 1] > ls[i]:
			if level[index] - 1 < 0:
				index += 1
			level[index] -= 1
		level[index + 1] += 1
	print(index + 1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	prev = a[1]
	ans = -1
	par = [-1] * (n + 1)
	par[a[1]] = 1
	d = [1, a[1]]
	j = 0
	for i in range(2, n):
		if a[i] > prev:
			par[a[i]] = d[j]
			d.append(a[i])
			prev = a[i]
		else:
			j += 1
			par[a[i]] = a[j]
			d.append(a[i])
			prev = a[i]
	while prev != -1:
		prev = par[prev]
		ans += 1
	print(ans)


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf():
	return [int(i) for i in get().split()]

def put(*a, sep=' ', end='\n'):
	stdout.write(sep.join([str(i) for i in a]) + end)
from math import log2, ceil
for _ in range(int(get())):
	n = int(get())
	a = getf()
	dcp = [1]
	cur = 0
	for i in range(1, n):
		if a[i - 1] < a[i]:
			cur += 1
		else:
			dcp.append(cur)
			cur = 1
	dcp.append(cur)
	i = 0
	curvc = 1
	ans = 0
	while i < n:
		y = 0
		for j in range(i + 1, min(len(dcp), i + curvc + 1)):
			y += dcp[j]
		i += curvc
		curvc = y
		ans += 1
	put(ans - 1)


t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	t = 0
	d = 1
	l = 1
	z = 0
	for i in range(2, n):
		if a[i] < a[i - 1]:
			t += 1
		z += 1
		if t >= l:
			d += 1
			l = z
			t = 0
			z = 0
	print(d)


import sys, os.path
from collections import *
from heapq import *
from copy import *
import math
mod = 10 ** 9 + 7
read = lambda : map(int, input().split())
inf = sys.maxsize
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 1
	if n == 2:
		print(1)
	else:
		q = deque()
		q.append(0)
		maxx = 1
		i = 1
		cur = 1
		while i < n:
			if i == 1 or a[i] < a[i - 1]:
				d = q[0]
				q.popleft()
				maxx = max(maxx, d + 1)
				cur = d + 1
				q.append(d + 1)
			else:
				q.append(cur)
			i += 1
		print(maxx)


import bisect
import math
import collections
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solution():
	n = inp()
	for _ in range(n):
		k = inp()
		a = inlt()
		print(solve(a, k))

def solve(a, k):
	prev_num = 0
	prev_lvl = 1
	cur_lvl = -1
	d = 1
	for num in a:
		if num > prev_num:
			cur_lvl += 1
		else:
			prev_lvl -= 1
			if prev_lvl == 0:
				d += 1
				prev_lvl = cur_lvl
				cur_lvl = 1
			else:
				cur_lvl += 1
		prev_num = num
	return d
solution()


for _ in range(int(input())):
	n = int(input())
	(*arr,) = map(int, input().split())
	n_intervals = 1
	ptr = 1
	cnt = 0
	while ptr < len(arr):
		start = ptr
		for interval_idx in range(n_intervals):
			while ptr < len(arr) and (ptr == len(arr) - 1 or arr[ptr] < arr[ptr + 1]):
				ptr += 1
			if ptr < len(arr):
				ptr += 1
		n_intervals = ptr - start
		cnt += 1
	print(cnt)


for t in range(int(input())):
	n = int(input())
	order = list(map(int, input().split()))
	par = 0
	from collections import defaultdict
	lvl = defaultdict(int)
	for i in range(1, n):
		if order[i - 1] > order[i]:
			par += 1
		lvl[i] = lvl[par] + 1
	print(lvl[n - 1])


import os
from heapq import heapify, heappop, heappush
import sys
import sys, threading
import math
import operator
import bisect
from collections import defaultdict
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		ar = inpt()
		(count, toAdd, ans, prev) = (1, 0, 1, 0)
		for i in range(n - 1):
			if ar[i + 1] > ar[i]:
				toAdd += 1
			elif count == 1:
				ans += 1
				prev = prev + toAdd
				toAdd = 0
				count = prev
			else:
				count -= 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = LI()
	d = [0] * n
	d[1] = 1
	count = 0
	for i in range(2, n):
		if a[i] < a[i - 1]:
			count += 1
		d[i] = d[count] + 1
	print(d[-1])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 1
	p = 0
	levelCompleted = 0
	for i in range(1, n):
		if a[i - 1] < a[i]:
			p += 1
		elif levelCompleted == 0:
			ans += 1
			levelCompleted = p - 1
		else:
			levelCompleted = levelCompleted - 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		ans = 1
		level = {}
		f = True
		i = 1
		k = 1
		while i < n:
			if a[i] > a[i - 1]:
				if k + 1 in level:
					level[k + 1] += 1
				elif k in level:
					level[k] += 1
				else:
					level[k] = 1
			elif level[k]:
				level[k] -= 1
				if k + 1 in level:
					level[k + 1] += 1
				else:
					level[k + 1] = 1
			else:
				k += 1
				level[k + 1] = 1
				level[k] -= 1
			i += 1
		print(max(level))


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
pr = lambda x: x

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	for _ in range(int(input())):
		(n,) = aj()
		A = aj()
		d = deque()
		d.append((A[0], 0))
		d.append((A[1], 1))
		for i in range(2, n):
			if A[i] < d[-1][0]:
				d.popleft()
			d.append((A[i], d[0][1] + 1))
		print(d[-1][-1])
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	from aj import *
except:
	pass
solve()


import sys
from sys import stdout
import io, os
input = lambda : sys.stdin.readline().strip()
P = lambda : list(map(int, input().split()))
from math import factorial as f, gcd
from collections import deque, defaultdict as dd, Counter as C
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge
from random import randint, choice, sample
import time
mod = 10 ** 9 + 7
a = ord('a')
start = time.time()

def fast_exp(x, exp):
	ans = 1
	base = x
	while exp:
		if exp & 1:
			ans *= base
		base *= base
		base %= mod
		ans %= mod
		exp >>= 1
	return ans

def countBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count

def submasks(n):
	org = n
	while n:
		yield n
		n = n - 1 & org

def solve():
	n = int(input())
	l = P()
	prev = float('inf')
	ans = 0
	branches = 0
	left = 0
	for x in l[1:]:
		if x > prev:
			branches += 1
		elif left:
			left -= 1
		else:
			left = branches
			ans += 1
		prev = x
	print(ans)
tc = int(input())
for t in range(1, tc + 1):
	solve()


for _ in range(int(input())):
	input()
	a = [int(x) for x in input().split()]
	y = a[1]
	b = [1, 1]
	for x in a[2:]:
		if x > y:
			b[-1] += 1
		else:
			b += [1]
		y = x
	levels = 0
	cur_level = [b.pop(0)]
	ptr = 0
	B = len(b)
	while ptr < B:
		next_level = []
		while cur_level != []:
			n = cur_level.pop(0)
			next_level += b[ptr:ptr + n]
			ptr += n
		cur_level = next_level
		levels += 1
	print(levels)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 1
	c = 0
	level = 0
	for i in range(1, n):
		if l[i] > l[i - 1]:
			c += 1
		elif level == 0:
			ans += 1
			level = c - 1
		else:
			level -= 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 1
	parent = 1
	child = 1
	i = 1
	cnt = 0
	while i < n - 1:
		if a[i] < a[i + 1]:
			child += 1
			i += 1
		elif cnt < parent - 1:
			cnt += 1
			child += 1
			i += 1
		else:
			parent = child
			child = 1
			ans += 1
			i += 1
			cnt = 0
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(c, p, q) = (1, 0, 0)
	for j in range(1, n):
		if a[j] > a[j - 1]:
			p = p + 1
		elif q == 0:
			c = c + 1
			q = p - 1
		else:
			q = q - 1
	print(c)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def solve():
	n = N()
	ar = lis()
	cl = deque([ar[0]])
	j = 1
	h = 0
	nl = []
	while cl:
		v = cl.popleft()
		if j < n:
			m = ar[j]
			nl.append(m)
			j += 1
		while j < n and ar[j] > m:
			m = ar[j]
			nl.append(ar[j])
			j += 1
		if not cl:
			cl = deque(nl)
			if nl:
				nl = []
				h += 1
	if nl:
		h += 1
	print(h)
testcase(int(inp()))


for tt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(i, ans, leaf) = (1, 0, 1)
	toAdd = 0
	while i < n:
		toAdd += 1
		i += 1
		while i < n and a[i] > a[i - 1]:
			toAdd += 1
			i += 1
		if leaf - 1:
			leaf -= 1
		else:
			ans += 1
			leaf += toAdd - 1
			toAdd = 0
	print(ans + (toAdd > 0))


from collections import defaultdict

def read_int() -> int:
	return int(input())

def read_ints():
	return map(int, input().split(' '))

def test_case():
	n = read_int()
	vertices = read_ints()
	levels = defaultdict(list)
	levels[0].append(next(vertices))
	current_parent = (0, 0)
	current_level = 1
	prev_vertex = None
	for current_vertex in vertices:
		if prev_vertex is not None:
			if current_vertex <= prev_vertex:
				(level_, pos_) = current_parent
				if len(levels[level_]) > pos_ + 1:
					current_parent = (level_, pos_ + 1)
				else:
					current_parent = (level_ + 1, 0)
					current_level += 1
		levels[current_level].append(current_vertex)
		prev_vertex = current_vertex
	print(len(levels) - 1)
for _ in range(read_int()):
	test_case()


import sys
import io, os
input = sys.stdin.buffer.readline
t = int(input())
from collections import deque
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	cnt = 0
	X = []
	for i in range(1, n):
		if A[i] > A[i - 1]:
			cnt += 1
			continue
		else:
			X.append(cnt)
			cnt = 1
	else:
		if cnt:
			X.append(cnt)
	X.reverse()
	ans = 0
	q = deque([])
	s = X.pop()
	q.append((s, 1))
	ans = 0
	while q:
		(v, d) = q.popleft()
		ans = max(ans, d)
		for i in range(v):
			if X:
				u = X.pop()
				q.append((u, d + 1))
			else:
				break
	print(ans)


from collections import deque, defaultdict

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	h = c = 1
	x = cl = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			x += 1
		if x == c:
			h += 1
			c = cl
			cl = x = 0
		cl += 1
	print(h)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 1
	cnt_old = 1
	cnt = 1
	for i in range(2, n):
		if a[i - 1] < a[i]:
			cnt_old += 1
		else:
			cnt -= 1
			if cnt == 0:
				ans += 1
				cnt = cnt_old
				cnt_old = 0
			cnt_old += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 1
	w = 0
	ans = 1
	for i in range(1, n):
		if l[i] < l[i - 1]:
			c -= 1
			if c == 0:
				c = w
				w = 1
				ans += 1
			else:
				w += 1
		else:
			w += 1
	print(ans)


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 1
	d = defaultdict(int)
	level = 1
	left = 0
	for j in range(2, n):
		if a[j] > a[j - 1]:
			c += 1
		else:
			d[level] += c
			if left:
				left -= 1
			else:
				left = d[level] - 1
				level += 1
			c = 1
	print(level)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	up = 1
	ans = 1
	temp = 1
	for i in range(2, n):
		if a[i] > a[i - 1]:
			temp += 1
		else:
			up -= 1
			if up > 0:
				temp += 1
			else:
				ans += 1
				up = temp
				temp = 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	x = 1
	newx = 1
	ans = 0
	i = 1
	while i < n:
		ans += 1
		prev = 0
		x = newx
		newx = 0
		while i < n and x:
			x -= 1
			prev = 0
			while i < n and s[i] > prev:
				prev = s[i]
				i += 1
				newx += 1
	print(ans)


import sys
import math, bisect
sys.setrecursionlimit(10 ** 6)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict

def I():
	return int(sys.stdin.readline())

def neo():
	return map(int, sys.stdin.readline().split())

def Neo():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = I()
	a = Neo()
	up = 1
	ans = 1
	temp = 1
	for i in range(2, n):
		if a[i] > a[i - 1]:
			temp += 1
		else:
			up -= 1
			if up > 0:
				temp += 1
			else:
				ans += 1
				up = temp
				temp = 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(lambda x: int(x), input().split()))
	count = 0
	h = [0]
	for i in range(1, n):
		if a[i - 1] > a[i]:
			count += 1
		h.append(h[count] + 1)
	print(h[-1])


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	A = getInts()
	levels = [1]
	(inc, dec) = (0, 0)
	for i in range(1, N):
		if A[i - 1] < A[i] or not inc + dec:
			inc += 1
		else:
			dec += 1
			if dec >= levels[-1]:
				levels.append(inc + dec - 1)
				inc = 1
				dec = 0
	levels.append(inc + dec)
	levels = levels[1:]
	return len(levels)
for _ in range(getInt()):
	print(solve())


def rl():
	return list(map(int, input().split()))

def ri():
	return int(input())

def rm():
	return map(int, input().split())

def solve():
	n = ri()
	a = rl()
	(i, j) = (1, 2)
	p = 1
	tmp = 0
	l = 0
	while i < n:
		p -= 1
		while j < n and a[j] > a[j - 1]:
			j += 1
		tmp += j - i
		i = j
		j += 1
		if p == 0:
			p = tmp
			l += 1
			tmp = 0
		elif i == n:
			l += 1
	return l
t = ri()
for i in range(t):
	print(solve())


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
for _ in range(II()):
	n = II()
	aa = LI()
	ans = 1
	par = 1
	chi = 0
	for i in range(n - 1):
		if aa[i + 1] < aa[i]:
			if par == 1:
				(par, chi) = (chi, 0)
				ans += 1
			else:
				par -= 1
		chi += 1
	print(ans)


t = int(input())

def solve(an):
	N = len(an)
	depth = [0] * N
	current_root = 0
	for i in range(1, N):
		if i - 1 > 0 and an[i - 1] > an[i]:
			current_root += 1
		depth[i] = depth[current_root] + 1
	return depth[-1]
for _ in range(t):
	n = int(input())
	an = list(map(int, input().split()))
	print(solve(an))


for cnt in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	res = 1
	pcnt = 1
	ccnt = 0
	for i in range(1, n - 1):
		ccnt += 1
		if t[i] >= t[i + 1]:
			pcnt -= 1
			if pcnt == 0:
				pcnt = ccnt
				ccnt = 0
				res += 1
	print(res)


for count in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	res = 1
	pcount = 1
	ccount = 0
	for i in range(1, n - 1):
		ccount += 1
		if t[i] >= t[i + 1]:
			pcount -= 1
			if pcount == 0:
				pcount = ccount
				ccount = 0
				res += 1
	print(res)


for df in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	s.pop(0)
	a = 1
	c = 1
	x = 1
	for i in range(n - 2):
		if s[i] < s[i + 1]:
			a += 1
		else:
			c -= 1
			if c == 0:
				x += 1
				c = a
				a = 1
			else:
				a += 1
	print(x)


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	print(' '.join(list(map(str, a))))

def solve():
	n = I()
	a = L()
	ans = 0
	c = 0
	l = 0
	r = 1
	for i in range(1, n):
		if a[i] > a[i - 1]:
			c += 1
		else:
			l += 1
			if l == r:
				ans += 1
				r = c + l - 1
				l = 0
				c = 1
	if c + l:
		ans += 1
	print(ans)
for _ in range(I()):
	solve()


for x in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	z = 1
	k = 1
	p = 1
	for i in range(2, n):
		if m[i] < m[i - 1]:
			z -= 1
		if z == 0:
			z = i - p
			p = i
			k += 1
	print(k)


from collections import deque
from copy import deepcopy as dcopy
t = int(input())
for test in range(t):
	n = int(input())
	bfs = list(map(int, input().strip().split()))
	adjacent_arr = [[] for i in range(n + 1)]
	previous = [bfs[0], 0]
	root = [bfs[0], 0]
	n = len(bfs)
	queue = deque()
	level = 0
	max_level = 0
	for i in range(1, n):
		if bfs[i] > previous[0]:
			adjacent_arr[root[0]].append(bfs[i])
			curr_previous = [bfs[i], root[1] + 1]
			previous = dcopy(curr_previous)
			max_level = max(previous[1], max_level)
			queue.append(curr_previous)
		else:
			root = queue.popleft()
			adjacent_arr[root[0]].append(bfs[i])
			curr_previous = [bfs[i], root[1] + 1]
			previous = dcopy(curr_previous)
			queue.append(curr_previous)
			max_level = max(previous[1], max_level)
	print(max_level)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	(height, max_slots, new_slots, cur_slot) = (1, 1, 0, 0)
	for i in range(1, n):
		if arr[i] >= arr[i - 1]:
			new_slots += 1
		else:
			cur_slot += 1
			if cur_slot < max_slots:
				new_slots += 1
			else:
				height += 1
				cur_slot = 0
				max_slots = new_slots
				new_slots = 1
	print(height)


n = int(input())
result = []
for i in range(n):
	lenlen = input()
	ver = list(map(int, input().split()))
	deep = 1
	if len(ver) == 0:
		result.append(0)
	else:
		prev_child_am = 0
		prev = ver[1]
		child_am = 1
		for i in range(2, len(ver)):
			if ver[i] < prev:
				if prev_child_am > 0:
					prev_child_am -= 1
					child_am += 1
				else:
					deep += 1
					prev_child_am = child_am - 1
					child_am = 1
			else:
				child_am += 1
			prev = ver[i]
		result.append(deep)
for i in result:
	print(i)


import sys
from bisect import bisect_left
t = int(sys.stdin.readline().strip())
for _ in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	dis = [0 for i in range(n)]
	idx = 0
	for j in range(1, n):
		if a[j] < a[j - 1]:
			idx += 1
		dis[j] = dis[idx] + 1
	print(dis[n - 1])


from collections import defaultdict
for i in range(100000):
	c = 5
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	if n == 1:
		print(0)
	else:
		i = 1
		ans = 0
		level = defaultdict(int)
		now = [l[0]]
		while i < n:
			z = now.pop(0)
			yo = []
			while i < n - 1 and l[i] < l[i + 1]:
				yo.append(l[i])
				i += 1
			yo.append(l[i])
			for j in yo:
				level[j] = level[z] + 1
			now += yo
			i += 1
		for i in level:
			ans = max(ans, level[i])
		print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		level = 1
		alpha = 1
		beta = 1
		for i in range(2, n):
			if a[i] > a[i - 1]:
				alpha += 1
				beta += 1
			else:
				beta += 1
				if beta > alpha:
					level += 1
					beta = 1
		print(level)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(currNode, prevNode, curr, ans, idx) = (0, 1, 1, 0, 1)
	while idx < n:
		if l[idx] < l[idx - 1]:
			curr += 1
		currNode += 1
		idx += 1
		if curr >= prevNode:
			ans += 1
			prevNode = currNode
			curr = 0
			currNode = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = []
	i = 1
	j = 2
	while j < n:
		if l[j] >= l[j - 1]:
			j += 1
		else:
			k.append(j - i)
			i = j
			j += 1
	k.append(j - i)
	ans = 0
	x = 1
	s = 0
	i = 0
	j = 0
	while j < len(k):
		if j - i < x:
			s += k[j]
			j += 1
		else:
			ans += 1
			x = s
			s = 0
			i = j
	ans += 1
	print(ans)


from collections import deque
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split(' ')))
	que = deque([0])
	(d, pos) = (0, n + 1)
	for x in a[1:]:
		if pos > x:
			d = que.popleft() + 1
		que.append(d)
		pos = x
	print(que[-1])


from sys import stdin, stdout
import collections, heapq, bisect, math
input = stdin.readline

def rint():
	return int(input())

def rstr():
	return input().strip()

def rlstr():
	return list(input().strip().split())

def rlint():
	return list(map(int, input().split()))

def main():
	n = rint()
	a = rlint()
	d = 0
	i = 1
	count = 1
	while i < n:
		temp = 0
		for _ in range(count):
			while i + 1 < n and a[i] <= a[i + 1]:
				temp += 1
				i += 1
			temp += 1
			i += 1
		d += 1
		count = temp
	print(d)
for _ in range(rint()):
	main()


from collections import deque
import sys
input = sys.stdin.readline
for j in range(int(input())):
	n = int(input())
	vals = list(map(int, input().split()))
	seg = [1]
	for s in range(2, n):
		if vals[s] >= vals[s - 1]:
			seg[-1] += 1
		else:
			seg.append(1)
	height = 0
	queue = deque([1, 0])
	for s in range(len(seg)):
		if queue[-1] == 0:
			height += 1
		queue[-1] += seg[s]
		queue[0] -= 1
		if queue[0] == 0:
			queue.popleft()
			queue.append(0)
	print(height)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(RL())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // gcd(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from itertools import groupby

def main():
	for _ in range(N()):
		n = N()
		arr = RLL()
		rec = [1]
		for i in range(2, n):
			if arr[i] > arr[i - 1]:
				rec[-1] += 1
			else:
				rec.append(1)
		pre = [1, 0]
		for i in rec:
			pnum = pre[-2]
			if pnum > 0:
				pre[-1] += i
				pre[-2] -= 1
			if pre[-2] == 0:
				pre.append(0)
		if pre[-1] == 0:
			pre.pop()
		print(len(pre) - 1)
main()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	arr = deque(l())
	stack = deque()
	answer = 0
	stack.append([arr.popleft(), 0])
	while arr:
		(a, b) = stack.popleft()
		answer = max(answer, b)
		if len(arr) == 1 or arr[0] > arr[1]:
			stack.append([arr.popleft(), b + 1])
			continue
		j = 0
		for i in range(1, len(arr)):
			if arr[i] > arr[i - 1]:
				j = i
				continue
			break
		for i in range(j + 1):
			stack.append([arr.popleft(), b + 1])
	while stack:
		answer = max(answer, stack.popleft()[1])
	out(answer)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = [[arr[1]]]
	for i in range(1, n - 1):
		if arr[i] < arr[i + 1]:
			res[-1].append(arr[i + 1])
		else:
			res.append([arr[i + 1]])
	l = []
	for a in res:
		l.append(len(a))
	i = 0
	j = 0
	s = [1]
	while i < len(l):
		s.append(sum(l[i:min(len(l), i + s[j])]))
		i += s[j]
		j += 1
	print(len(s) - 1)


from queue import Queue
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	minimal_height = 1
	parents = 1
	current_floor_children = 1
	children = Queue()
	for i in range(2, len(arr)):
		if arr[i] < arr[i - 1]:
			parents -= 1
			if parents == 0:
				minimal_height += 1
				children.put(current_floor_children)
				current_floor_children = 1
				parents = children.get()
			else:
				current_floor_children += 1
		else:
			current_floor_children += 1
	print(minimal_height)


for _ in range(int(input())):
	(n, a) = (int(input()), list(map(int, input().split())))
	h = [0] * n
	last = 0
	for i in range(0, n - 1):
		if a[i] > a[i + 1]:
			last += 1
		h[i + 1] = h[last] + 1
	print(h[-1])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from collections import deque
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 2:
		print(1)
		continue
	inc = 1
	u = []
	for i in range(2, n):
		if a[i] > a[i - 1]:
			inc += 1
		else:
			u += [inc]
			inc = 1
	if inc:
		u += [inc]
	depth = 0
	dx = [0] * (n + 69)
	dx[0] = 1
	dq = deque(u)
	while dq:
		p = False
		for i in range(dx[depth]):
			if dq:
				dx[depth + 1] += dq.popleft()
				p = True
			else:
				break
		if p:
			depth += 1
	print(depth)


import sys
from collections import defaultdict, deque
input = sys.stdin.readline

def h(g, v):
	q = deque([v])
	x = 0
	while q:
		c = len(q)
		x += 1
		while c > 0:
			v = q.popleft()
			for i in g[v]:
				q.append(i)
			c -= 1
	return x
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if lis == sorted(lis):
		print(1)
		continue
	g = defaultdict(list)
	res = deque([1])
	j = 1
	s = set()
	while True:
		try:
			x = res.popleft()
		except:
			break
		if lis[j] in s:
			break
		g[x].append(lis[j])
		res.append(lis[j])
		if j == n - 1:
			break
		for i in range(j, n - 1):
			if lis[i] > lis[i + 1]:
				break
			g[x].append(lis[i + 1])
			res.append(lis[i + 1])
			s.add(lis[i + 1])
		j = i + 1
	print(h(g, 1) - 1)


import sys, collections
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	heights = [0] * n
	cur = 0
	for i in range(1, n):
		if A[i - 1] > A[i]:
			cur += 1
		heights[i] = heights[cur] + 1
	print(heights[-1])


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
from itertools import *
from heapq import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	if n == 1:
		print(0)
		continue
	p = a[1]
	co = 0
	v = []
	for i in range(1, n):
		if a[i] >= p:
			p = a[i]
			co += 1
			continue
		else:
			if co <= 1:
				v.append(0)
			else:
				v.append(co)
			p = a[i]
			co = 1
	if co <= 1:
		v.append(0)
	else:
		v.append(co)
	if len(v) == 1:
		print(1)
		continue
	ss = v[0]
	mh = 1
	j = 1
	while 1:
		ss1 = ss
		ss = 0
		fl = 0
		for i in range(ss1):
			if j < len(v):
				fl = 1
				ss += max(1, v[j])
			j += 1
		if fl:
			mh += 1
		if j >= len(v):
			break
		if ss1 == 0:
			ss = v[j]
			j += 1
			mh += 1
	print(mh)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations, combinations

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = int(1000000000.0) + 7
for t in range(int(data())):
	n = int(data())
	a = mdata() + [0]
	s1 = 0
	s2 = 1
	ans = 0
	for i in range(1, n):
		if s1 == 0:
			ans += 1
			(s1, s2) = (s2, 0)
		s2 += 1
		if a[i] > a[i + 1]:
			s1 -= 1
	out(ans)


gans = []
for _ in range(int(input())):
	n = int(input())
	u = list(map(int, input().split()))
	if n == 1:
		gans.append(0)
		continue
	lvl = [0]
	ind = 0
	cur = 0
	cnt = 1
	for i in range(1, n):
		if u[i] > cur:
			lvl[ind] += 1
			cur = u[i]
		elif ind < len(lvl) - 1:
			ind += 1
			lvl[ind] += 1
			cur = u[i]
		else:
			lvl = [0] * sum(lvl)
			ind = 0
			cnt += 1
			lvl[ind] += 1
			cur = u[i]
	gans.append(cnt)
print(*gans, sep='\n')


from collections import deque
from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.append(float('inf'))
	d = deque([])
	d.append((1, 1))
	index = 1
	mx = 1
	while index < n:
		(x, y) = d.popleft()
		mx = max(mx, y)
		d.append((a[index], y + 1))
		while index < n and a[index] < a[index + 1]:
			index += 1
			d.append((a[index], y + 1))
		index += 1
	stdout.write(str(mx) + '\n')


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	q = [[0, 0]]
	curr = 1
	while len(q) != 0:
		(a, b) = q.pop(0)
		if a == n - 1:
			print(b)
			break
		prev = -1
		while curr < n and arr[curr] > prev:
			q.append([curr, b + 1])
			prev = arr[curr]
			curr += 1
		if curr == n:
			print(b + 1)
			break


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 1
	if n == 1:
		print(0)
		continue
	np = 1
	nnp = 0
	c = 1
	while i < n - 1:
		if np == 0:
			np = nnp
			nnp = 0
			c += 1
		if arr[i] > arr[i + 1]:
			np -= 1
		nnp += 1
		i += 1
	if np == 0:
		np = nnp
		nnp = 0
		c += 1
	print(c)


from queue import Queue
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	(profundidade, indice, qtd_nos) = (0, 1, 1)
	q = Queue()
	q.put(1)
	while not q.empty():
		nos_proximo_nivel = 0
		for i in range(qtd_nos):
			q.get()
			atual = -1
			while indice < n:
				if a[indice] < atual:
					break
				atual = a[indice]
				q.put(a[indice])
				indice += 1
				nos_proximo_nivel += 1
		qtd_nos = nos_proximo_nivel
		if q.qsize():
			profundidade += 1
	print(profundidade)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	nodes = 1
	newNodes = 1
	ans = 1
	totBreaks = 0
	for i in range(2, n):
		if arr[i] > arr[i - 1]:
			newNodes += 1
		else:
			totBreaks += 1
			if totBreaks >= nodes:
				totBreaks = 0
				nodes = newNodes
				ans += 1
	print(ans)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 32, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	cur = 1
	res = 0
	ans = 0
	for i in range(1, n):
		if i != 1 and l[i] > l[i - 1]:
			cur += 1
		elif res > 0:
			res -= 1
			cur += 1
		else:
			ans += 1
			res = cur
			cur = 1
			res -= 1
	print(ans)


import sys

def answer(n, a):
	if n == 2:
		return 1
	lvl = [0 for _ in range(n + 1)]
	lvl[0] = 0
	lvl[1] = 1
	pptr = 0
	cptr = 2
	while cptr < n:
		if a[cptr] > a[cptr - 1]:
			lvl[cptr] = lvl[cptr - 1]
			cptr += 1
		else:
			pptr += 1
			if lvl[pptr] == lvl[pptr - 1]:
				lvl[cptr] = lvl[cptr - 1]
				cptr += 1
			else:
				lvl[cptr] = lvl[cptr - 1] + 1
				cptr += 1
	return lvl[cptr - 1]

def main():
	t = int(sys.stdin.readline())
	while t:
		n = int(sys.stdin.readline())
		a = list(map(int, sys.stdin.readline().split()))
		print(answer(n, a))
		t -= 1
	return
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	cur = 1
	res = 0
	ans = 0
	for i in range(1, n):
		if i != 1 and l[i] > l[i - 1]:
			cur += 1
		elif res > 0:
			res -= 1
			cur += 1
		else:
			ans += 1
			res = cur
			cur = 1
			res -= 1
	print(ans)


tests = int(input())
for test in range(tests):
	n = int(input())
	a = [int(i) for i in input().split()][1:]
	b = [1]
	for i in range(1, n - 1):
		if a[i] > a[i - 1]:
			b[-1] += 1
		else:
			b.append(1)
	u = 0
	c = 1
	ans = 1
	while u + c < len(b):
		ans += 1
		(u, c) = (u + c, sum(b[u:u + c]))
	print(ans)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from typing import List
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

@lru_cache(None)
def fact(x, mod=0):
	if x < 2:
		return 1
	if not mod:
		return fact(x - 1) * x
	return fact(x - 1, mod) * x % mod

@lru_cache(None)
def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	ans = 1
	for k in range(i - j + 1, i + 1):
		ans = ans * k % mod
	return ans

@lru_cache(None)
def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j) * inverse(fact(j), mod) % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d
t = N()
for i in range(t):
	n = N()
	a = RLL()
	ans = last = 1
	g = 1
	cur = 0
	for j in range(1, n):
		if a[j] < a[j - 1]:
			if g == last:
				last = cur
				ans += 1
				g = 1
				cur = 1
			else:
				g += 1
				cur += 1
		else:
			cur += 1
	print(ans)


from collections import deque
T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	d[0] = 1
	i = 1
	while i < n:
		tmp = i
		d[tmp] = 1
		i += 1
		while i < n and a[i] > a[i - 1]:
			i += 1
			d[tmp] += 1
	ans = 0
	i = 0
	sz = 0
	lst = [(k, v) for (k, v) in d.items()]
	lst.sort()
	ptr = 0
	tmp_sz = 1
	sizes = []
	while ptr < len(lst):
		sz = tmp_sz
		tmp_sz = 0
		for j in range(sz):
			if ptr >= len(lst):
				break
			tmp_sz += lst[ptr][1]
			ptr += 1
		sizes.append(tmp_sz)
	print(len(sizes) - 1)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	grafo = [1, 1]
	i = 2
	j = 1
	while i < n:
		filho = a[i - 1]
		if a[i] < filho:
			grafo.append(1)
			j += 1
		else:
			grafo[j] += 1
		i += 1
	i = 0
	s = 0
	lim = 1
	prof = 0
	while i < j:
		if i + lim <= j:
			for k in range(i, i + lim):
				s += grafo[k]
			prof += 1
		i += lim
		lim = s
		s = 0
	print(prof)
	t -= 1


def main():
	n = int(input())
	a = list(map(int, input().split()))
	depth = 0
	prev = 1
	parents = [a[1]]
	heights = dict()
	k = 0
	heights[a[1]] = 1
	cur_mx = a[1]
	for i in range(2, n):
		if a[i] < cur_mx:
			heights[a[i]] = heights[parents[k]] + 1
			k += 1
			cur_mx = a[i]
		else:
			heights[a[i]] = heights[parents[k]]
			cur_mx = a[i]
		parents.append(a[i])
	print(max(heights.values()))
t = int(input())
for i in range(t):
	main()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	assert A[0] == 1
	chunks = []
	for x in A[1:]:
		if not chunks or chunks[-1][-1] > x:
			chunks.append([x])
		else:
			chunks[-1].append(x)
	chunks = deque(chunks)
	depth = {1: 0}
	q = deque([1])
	while q:
		node = q.popleft()
		d = depth[node]
		if chunks:
			for c in chunks.popleft():
				depth[c] = d + 1
				q.append(c)
	return max(depth.values())
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
from collections import deque
for _ in range(II()):
	(n, a) = (II(), LI())
	(p, c) = (deque([1]), deque([]))
	ans = 1
	for i in range(1, n):
		if a[i] < a[i - 1]:
			p.popleft()
		if not p:
			p = c.copy()
			c.clear()
			ans += 1
		c.append(a[i])
	print(ans)


import math
from math import gcd
from functools import reduce
from sys import maxsize

def power(x, y):
	res = 1
	while y > 0:
		if y & 1 == 1:
			res = res * x
		y = y >> 1
		x = x * x
	return res

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def findprime(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p ** 2 <= n:
		if prime[p]:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p += 1
	for i in range(2, n + 1):
		if prime[i]:
			print(i)

def gcd(a, b):
	if b == 0:
		return a
	return int(gcd(b, a % b))

def lcm(a, b):
	return int(a * b / gcd(a, b))

def gcdl(denominators):
	return int(reduce(lambda a, b: gcd(a, b), denominators))

def lcml(denominators):
	return int(reduce(lambda a, b: a * b // gcd(a, b), denominators))

def queuepop(l):
	return (l[1:], l[0])

def bfs(d, a, n):
	visited = [False for i in range(n)]
	q = []
	q.append(a)
	visited[a] = True
	while len(q):
		(q, s) = queuepop(q)
		print(s, end=' ')
		for i in d[s]:
			if not visited[i]:
				visited[i] = True
				q.append(i)
	print()

def dfsutil(d, a, visited):
	visited[a] = True
	print(a, end=' ')
	for i in d[a]:
		if not visited[i]:
			dfsutil(d, i, visited)

def dfs(d, a, n):
	visited = [False for i in range(n)]
	dfsutil(d, a, visited)
	print()

def printgraph(d):
	for (i, j) in d.items():
		print(i, ': ', *j)
import sys
from collections import defaultdict as df

def ini():
	return int(sys.stdin.readline())

def inp():
	return map(int, sys.stdin.readline().strip().split())

def li():
	return list(map(int, sys.stdin.readline().strip().split()))
t = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 3, 3, 3, 3, 3, 4, 2, 2, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 3, 3, 3, 3, 3, 4, 3, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 5, 5, 5, 4, 4, 4, 5, 5, 5, 5, 6]
for _ in range(ini()):
	n = ini()
	l = li()
	a = 1
	b = 1
	c = 1
	for i in range(2, n):
		if l[i - 1] < l[i]:
			a += 1
		else:
			b -= 1
			if b == 0:
				c += 1
				b = a
				a = 1
			else:
				a += 1
	print(c)


for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = 0
	i = 1
	num1 = 1
	num2 = 0
	while i < n:
		ans += 1
		while i < n and num1 > 0:
			num2 += 1
			while i < n - 1 and ar[i] < ar[i + 1]:
				num2 += 1
				i += 1
			num1 -= 1
			i += 1
		num1 = num2
		num2 = 0
	print(ans)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(c, p, q) = (1, 0, 0)
	for i in range(1, n):
		if a[i - 1] < a[i]:
			p += 1
		elif q == 0:
			c += 1
			q = p - 1
		else:
			q -= 1
	print(c)


import sys
from collections import deque
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(n, ar) = (int(input()), deque(map(int, input().split())))
	(child, ls) = (deque([]), [])
	for u in range(1, n):
		ls.append(ar[u])
		if u == n - 1 or ar[u] > ar[u + 1]:
			child.append(ls)
			ls = []
	h = {1: 0}
	while child:
		(p, ls) = (ar.popleft(), child.popleft())
		for u in ls:
			h[u] = h[p] + 1
	print(max(h.values()))


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline
sys.setrecursionlimit(300000)
mod = 10 ** 9 + 7
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	ans = 0
	c = 1
	i = 1
	while c:
		nc = 0
		while c and i < n:
			curr = 1
			while i < n - 1 and arr[i] < arr[i + 1]:
				curr += 1
				i += 1
			nc += curr
			i += 1
			c -= 1
		if nc:
			ans += 1
		c = nc
	print(ans)


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	last = 1
	prev_children = 1
	children = 0
	h = 1
	for i in range(1, n):
		cur = a[i]
		if cur > last:
			children += 1
		else:
			prev_children -= 1
			if prev_children == 0:
				h += 1
				prev_children = children
				children = 0
			children += 1
		last = cur
	print(h)


for i in range(int(input())):
	n = int(input())
	d = [0] * n
	dinh = list(map(int, input().split()))
	queue = []
	queue.append(0)
	l = 1
	r = 1
	dinh.append(-1)
	d[0] = 0
	d[1] = 1
	while dinh[r] != -1:
		pgoc = queue.pop(0)
		d[r] = d[pgoc] + 1
		queue.append(r)
		while dinh[r + 1] > dinh[r]:
			r += 1
			d[r] = d[pgoc] + 1
			queue.append(r)
		r += 1
		l = r
	print(d[n - 1])


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	(curr, f, j) = (1, 0, 1)
	level = 0
	while j < n:
		cnt = 1
		while j < n - 1 and a[j + 1] > a[j]:
			cnt += 1
			j += 1
		f += cnt
		curr -= 1
		if curr != 0 and j == n - 1:
			level += 1
		if curr == 0:
			curr = f
			f = 0
			level += 1
		j += 1
	print(level)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	levels = [0] * n
	index = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			index += 1
		levels[i] = levels[index] + 1
	print(levels[-1])


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	N = INT()
	A = LIST()
	A.reverse()
	nodes = [[[A.pop()]]]
	ans = 0
	while A:
		curdepth = []
		for pars in nodes[-1]:
			for par in pars:
				chlds = [-1]
				while A and A[-1] > chlds[-1]:
					chlds.append(A.pop())
				curdepth.append(chlds[1:])
			nodes.append(curdepth)
		ans += 1
	print(ans)


from collections import Counter
import string
import math
import bisect
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def put():
	for j in range(i + 1, n):
		if num[j] >= maxi:
			maxi = num[j]
			visited[j] = 1
			child += 1
		else:
			return
testcases = vary(1)
for _ in range(testcases):
	n = vary(1)
	num = array_int()
	ans = 0
	levels = [0] * (n + 1)
	ct = 0
	for i in range(1, n):
		if i - 1 > 0 and num[i - 1] > num[i]:
			ct += 1
		levels[i] = levels[ct] + 1
	print(levels[-2])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n < 3:
		print(1)
		continue
	old = [0]
	h = 1
	nind = prev = cum = 0
	for i in range(1, n):
		if a[i] < prev:
			nind += 1
			if nind >= len(old):
				old = [0] * cum
				nind = cum = 0
				h += 1
		prev = a[i]
		old[nind] += 1
		cum += 1
	print(h)


import sys

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		a = Ilist()
		x = [[1], []]
		incr = True
		for i in range(1, n):
			if a[i] > a[i - 1]:
				x[-1].append(a[i])
			else:
				x.append([])
				x[-1].append(a[i])
		nodes_parent = 1
		nodes_children = 0
		height = 0
		debug(x)
		for j in range(1, len(x)):
			lxj = len(x[j])
			if nodes_children == 0:
				height += 1
			nodes_children += lxj
			nodes_parent -= 1
			if nodes_parent == 0:
				nodes_parent = nodes_children
				nodes_children = 0
			debug(x[j], height, nodes_parent, nodes_children, c=4)
		print(height)
en = enumerate
FIO = 10
inf = float('inf')

def debug(*args, c=6):
	pass
BUFSIZE = 8 * 1024

def Istr():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 1
	k = 0
	nexk = 0
	for i in range(2, n):
		if a[i] < a[i - 1]:
			if k:
				k -= 1
				nexk += 1
			else:
				c += 1
				k = nexk
				nexk = 0
		else:
			nexk += 1
	print(c)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [int(word) for word in input().rstrip().split()]
		depth = 0
		fathers = 1
		sons = 0
		fa_iter = 0
		last = float('inf')
		for i in range(1, len(a)):
			if a[i] >= last:
				last = a[i]
				sons += 1
				continue
			fa_iter += 1
			if fa_iter >= fathers:
				depth += 1
				fathers = sons
				fa_iter = 0
				last = a[i]
				sons = 1
			else:
				last = a[i]
				sons += 1
		print(depth)
main()


for _ in range(int(input())):
	N = int(input())
	A = [int(x) for x in input().split()]
	last = i = j = 1
	ans = nxt = cur = 0
	while j < N:
		while j < N - 1 and A[j + 1] > A[j]:
			j += 1
		if cur == 0:
			ans += 1
		nxt += j - i + 1
		j += 1
		i = j
		cur += 1
		if cur == last:
			last = nxt
			nxt = cur = 0
	print(ans)


for _ in range(int(input())):
	n = input()
	nodes = list(map(int, input().split()))
	length = 1
	new_length = 0
	depth = 1
	prev = 0
	for i in nodes[1:]:
		if i > prev:
			q = 0
		else:
			length -= 1
		if length == 0:
			length = new_length
			new_length = 0
			depth += 1
		new_length += 1
		prev = i
	print(depth)


from sys import *
input = stdin.readline
import random
from bisect import *
import math
from collections import *
import operator
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	ans = 0
	levels = [0] * (n + 1)
	ct = 0
	for i in range(1, n):
		if i - 1 > 0 and num[i - 1] > num[i]:
			ct += 1
		levels[i] = levels[ct] + 1
	print(levels[-2])


import sys
sys.setrecursionlimit(10 ** 5 + 5)
from collections import defaultdict as dft, deque

def ml():
	return list(map(int, input().split()))

def mp():
	return map(int, input().split())
mxn = 10 ** 9

def solve():
	n = int(input())
	a = ml()
	if n == 1:
		print(0)
		return
	st = [[1, 0]]
	i = 1
	mn = 0
	arr = [1]
	temp = 0
	while i < n:
		if a[i] > mn:
			temp += 1
			mn = a[i]
			i += 1
			continue
		else:
			arr.append(temp)
			mn = 0
			temp = 0
	if temp:
		arr.append(temp)
	tsm = 0
	level = 1
	count = arr[0]
	res = 0
	i = 1
	while i < len(arr):
		if count:
			res = level
			tsm += arr[i]
			count -= 1
			i += 1
		else:
			count = tsm
			tsm = 0
			level += 1
	print(res)
t = int(input())
for _ in range(t):
	solve()


import sys
from collections import deque
from copy import *
from itertools import permutations as prm, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	n = fi()
	a = li()
	ans = 1
	r = [0] * (n + 5)
	r[0] = 1
	for i in range(1, n):
		if a[i] < a[i - 1]:
			if r[ans - 1] == 1:
				ans += 1
				r[ans] += 1
			else:
				r[ans - 1] -= 1
				r[ans] += 1
		else:
			r[ans] += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for q in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	j = 1
	l = 1
	curr = 1
	curr2 = 0
	while j < n:
		if j < n - 1 and b[j] < b[j + 1]:
			curr2 += 1
		elif j < n - 1 and b[j] > b[j + 1]:
			curr += -1
			curr2 += 1
			if curr == 0:
				curr = curr2
				curr2 = 0
				l += 1
		j += 1
	print(l)


from sys import stdin

def solve(n, nodes):
	root = nodes.pop(0) - 1
	height = 1
	count = 0
	for i in range(1, n - 1):
		count += 1
		if nodes[i] < nodes[i - 1]:
			if root > 0:
				root -= 1
			else:
				height += 1
				root = count - 1
				count = 0
	return height
for t in range(int(input())):
	n = int(input())
	nodes = list(map(int, stdin.readline().split()))
	print(solve(n, nodes))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	i = 1
	h = 0
	(p, k) = (1, 0)
	layer = []
	while i < n:
		if len(layer) == 0:
			layer.append(arr[i])
			i += 1
		elif arr[i] >= layer[-1]:
			layer.append(arr[i])
			i += 1
		else:
			k += len(layer)
			layer = []
			if p > 1:
				p -= 1
			else:
				h += 1
				p = k
				k = 0
	print(h + 1)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	p = inp()
	l = inlt()
	depth = 1
	space = 1
	node = 0
	pos = 1
	prev = 0
	while pos < p:
		id1 = l[pos]
		node += 1
		if id1 < prev:
			space -= 1
			if space == 0:
				depth += 1
				node -= 1
				space = node
				node = 1
				prev = id1
		prev = id1
		pos += 1
	print(depth)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	x = 0
	h = 1
	q = 0
	for i in range(1, n):
		if l[i] > l[i - 1]:
			x += 1
		elif q == 0:
			h += 1
			q = x - 1
		else:
			q -= 1
	print(h)


t = int(input())
from collections import deque

def sol():
	ch = {i: [] for i in range(n + 1)}
	i = 0
	j = 1
	while i < n:
		k = j
		j += 1
		while j < n and a[j] >= a[j - 1]:
			j += 1
		ch[a[i]] = a[k:j]
		i += 1
	return ch

def bfs():
	ch = sol()
	q = deque([1])
	dp = {i: 0 for i in range(n + 1)}
	while q:
		x = q.popleft()
		for y in ch[x]:
			q.append(y)
			dp[y] = dp[x] + 1
	return max(dp.values())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(bfs())


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	p = 0
	ans = 1
	c = 0
	for j in range(1, n):
		if a[j] > a[j - 1]:
			c += 1
		elif not p:
			ans += 1
			p = c - 1
		else:
			p -= 1
	print(ans)


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(d, c) = ([0] * n, 0)
	for i in range(1, n):
		if a[i - 1] > a[i]:
			c += 1
		d[i] = d[c] + 1
	print(d[n - 1])


import array

def solve():
	(n, ans, lv, c) = (int(input()), 1, 0, 0)
	a = array.array('i', map(int, input().split()))
	for i in range(1, n):
		if a[i] > a[i - 1]:
			c += 1
		elif lv == 0:
			(ans, lv) = (ans + 1, c - 1)
		else:
			lv -= 1
	print(ans)
T = int(input())
for Tid in range(T):
	solve()


import sys, os
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
mod = 10 ** 9 + 7

def main():
	ans = ''
	for _ in range(int(input())):
		n = int(input())
		arr = read() + [-10 ** 5 - 1]
		lvl_cnt = 1
		lvl = 0
		ind = 1
		while True:
			tem = 0
			while lvl_cnt:
				if ind == n:
					break
				if arr[ind] > arr[ind + 1]:
					lvl_cnt -= 1
				ind += 1
				tem += 1
			lvl_cnt = tem
			lvl += 1
			if ind == n:
				break
		ans += str(lvl) + '\n'
	print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	now_index = 0
	height = [0] * (n + 1)
	prev_value = 1
	for i in range(1, n):
		if prev_value > arr[i]:
			prev_value = arr[i]
			now_index += 1
			height[i] = height[now_index] + 1
		else:
			prev_value = arr[i]
			height[i] = height[now_index] + 1
	print(max(height))


t = int(input())
for t1 in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 1
	level = 0
	c = 0
	for i in range(1, n):
		if l[i - 1] < l[i]:
			c += 1
		elif level == 0:
			ans += 1
			level = c - 1
		else:
			level -= 1
	print(ans)


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	h = 1
	r = [1]
	u = 0
	d = 0
	for i in range(1, n):
		if a[i] > a[i - 1] or u + d == 0:
			u += 1
		else:
			d += 1
			if d >= r[-1]:
				r.append(u + d - 1)
				d = 0
				u = 1
	if u + d > 0:
		r.append(u + d)
	print(len(r) - 1)


for testcase in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	levels = [1]
	lastlevel = 0
	last = n + 3
	for i in a[1:]:
		if i < last:
			if lastlevel == 0:
				lastlevel = levels[-1]
				levels.append(0)
			lastlevel -= 1
		levels[-1] += 1
		last = i
	print(len(levels) - 1)


T = int(input())
for t in range(T):
	n = int(input())
	a = [0] + [int(i) for i in input().split()] + [0, 0, 0, 0, 0]
	res = 1
	lastcut = 1
	cnt = 1
	for i in range(3, n + 1):
		if a[i] < a[i - 1]:
			lastcut -= 1
			if lastcut == 0:
				res += 1
				lastcut = cnt
				cnt = 0
		cnt += 1
	print(res)


t = int(input())
for i10 in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	v = 1
	s1 = 1
	for i in range(1, n):
		if i == 1:
			s = 1
		elif a[i] < a[i - 1]:
			s1 -= 1
			if s1 == 0:
				s += 1
				s1 = v
				v = 1
			else:
				v += 1
		else:
			v += 1
	print(s)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return list(map(int, sys.stdin.readline().strip().split()))[0]

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
N = 0
a = []

def solve():
	global N
	N = get_int()
	a = get_list()
	totalParentsOfLastLevel = 1
	nodesAtCurrentLevel = 1
	answer = 1
	for i in range(2, N):
		if a[i] < a[i - 1]:
			totalParentsOfLastLevel = totalParentsOfLastLevel - 1
			if totalParentsOfLastLevel == 0:
				answer = answer + 1
				totalParentsOfLastLevel = nodesAtCurrentLevel
				nodesAtCurrentLevel = 1
				i = i + 1
			else:
				nodesAtCurrentLevel = nodesAtCurrentLevel + 1
		else:
			nodesAtCurrentLevel = nodesAtCurrentLevel + 1
	print(answer)
test_cases = get_int()
for _ in range(test_cases):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	height = 0
	currentnodes = 1
	nextnodes = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			currentnodes -= 1
			if currentnodes == 0:
				currentnodes = nextnodes
				nextnodes = 1
				height += 1
			else:
				nextnodes += 1
		else:
			nextnodes += 1
	if n == 1:
		print(0)
	else:
		print(height + 1)


for _ in range(int(input())):
	n = int(input())
	arr = [int(num) for num in input().split(' ')]
	ans = 1
	node_p = 1
	node_c = 0
	for i in range(1, n):
		if arr[i - 1] < arr[i]:
			node_c = node_c + 1
		else:
			node_p = node_p - 1
		if node_p == 0:
			ans = ans + 1
			node_p = node_c
			code_c = 0
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	visited = [(0, 0)]
	vispointer = 0
	for node in range(1, n):
		if arr[node] > arr[node - 1]:
			visited.append((arr[node], visited[vispointer][1] + 1))
		else:
			vispointer += 1
			visited.append((arr[node], visited[vispointer][1] + 1))
	print(visited[-1][1])


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	increasingGpSizes = [1]
	a.append(-1)
	prev = -1
	sz = 0
	for i in range(1, n + 1):
		if a[i] >= prev:
			sz += 1
		else:
			increasingGpSizes.append(sz)
			sz = 1
		prev = a[i]
	curTotalSz = 1
	ht = 0
	curAccumSz = 0
	curAccumCnt = 0
	for x in increasingGpSizes[1:]:
		curAccumCnt += 1
		curAccumSz += x
		if curAccumCnt == curTotalSz:
			ht += 1
			curTotalSz = curAccumSz
			curAccumSz = 0
			curAccumCnt = 0
	if curAccumCnt > 0:
		ht += 1
	print(ht)


import sys
input = sys.stdin.readline
for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	nad = 0
	pod = 0
	d = 1
	prev = 0
	for i in range(1, n):
		if a[i] > prev:
			pod += 1
			prev = a[i]
		elif nad > 0:
			nad -= 1
			pod += 1
			prev = a[i]
		else:
			nad = pod - 1
			pod = 1
			d += 1
			prev = a[i]
	print(d)


from sys import stdin
input = stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
		return
	lvl = 0
	pre = 1
	cur = 0
	i = 1
	while i < n:
		j = i
		while cur < pre:
			j += 1
			while j < n and a[j - 1] < a[j]:
				j += 1
			cur += 1
		pre = j - i
		cur = 0
		i = j
		lvl += 1
	print(lvl)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	input()
	a = list(map(int, input().split(' ')))
	q = [0]
	l = 0
	p = -1
	i = 1
	while i < len(a):
		if p < a[i]:
			p = a[i]
			q.append(q[l] + 1)
			i += 1
		else:
			p = -1
			l += 1
	print(max(q))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	li = []
	e = 0
	for j in range(1, n):
		if l[j] > l[j - 1]:
			e += 1
		else:
			li.append(e)
			e = 1
		if j == n - 1:
			li.append(e)
	prev = 0
	ind = 1
	h = 0
	while prev < len(li):
		h += 1
		ass = sum(li[prev:ind])
		prev = ind
		ind += ass
	print(h)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ANS = 1
	weight = 1
	now_weight = 1
	for i in range(2, n):
		if A[i] > A[i - 1]:
			weight += 1
			now_weight += 1
		else:
			now_weight += 1
			if now_weight > weight:
				ANS += 1
				now_weight = 1
	print(ANS)


def tree(arr):
	count = 0
	base = [0] * (len(arr) + 1)
	for i in range(1, len(arr)):
		if i - 1 > 0 and arr[i] < arr[i - 1]:
			count += 1
		base[i] = base[count] + 1
	return base[len(arr) - 1]
t = int(input())
for i in range(t):
	n = input()
	print(tree(list(map(int, input().strip().split()))))


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
from itertools import *

def fun():

	def solve():
		pass
	n = ii1()
	arr = iia()
	last = 0
	height = [inf] * n
	height[0] = 0
	for i in range(1, n):
		if i - 1 > 0 and arr[i - 1] > arr[i]:
			last += 1
		height[i] = height[last] + 1
	print(height[-1])
for i in range(ii1()):
	fun()


from queue import Queue
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	q = Queue()
	q.put((a[1], 1))
	(pos, res) = (2, 1)
	while not q.empty():
		(node, height) = q.get()
		while pos < n:
			if a[pos] < a[pos - 1]:
				q.put((a[pos], height + 1))
				res = max(res, height + 1)
				pos += 1
				break
			else:
				q.put((a[pos], height))
				pos += 1
	print(res)


for _ in range(int(input())):
	n = int(input())
	v = list(map(int, input().split()))
	(ind, cur, prev) = (1, 0, 0)
	if n == 1:
		print(1)
		continue
	ans = 1
	while ind < n:
		if v[ind] > v[ind - 1]:
			cur += 1
		elif prev == 0:
			ans += 1
			prev = cur
			cur = 1
		else:
			prev -= 1
			if prev == 0:
				ans += 1
				prev = cur
				cur = 1
			else:
				cur += 1
		ind += 1
	print(ans)


import sys
max_int = 1000000001
min_int = -max_int
t = int(input())
for _t in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	if len(a) == 1:
		print(0)
		continue
	cur_level = [0, 1]
	next_level = [0, 0]
	level = 1
	for aa in a[1:]:
		while cur_level[1]:
			if aa > cur_level[0]:
				cur_level[0] = aa
				next_level[1] += 1
				break
			else:
				cur_level[1] -= 1
				cur_level[0] = 0
		else:
			level += 1
			cur_level = [aa, next_level[1]]
			next_level = [0, 1]
	print(level)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(d, c) = ([0] * n, 0)
	for i in range(1, n):
		if l[i - 1] > l[i]:
			c += 1
		d[i] = d[c] + 1
	print(d[n - 1])


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
for _ in range(II()):
	n = II()
	l = LI()
	ans = 1
	prevcnt = 1
	cnt = 0
	for i in range(1, n - 1):
		cnt += 1
		if l[i + 1] < l[i]:
			if prevcnt > 1:
				prevcnt -= 1
			else:
				ans += 1
				prevcnt = cnt
				cnt = 0
	print(ans)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	level = 1
	cou = 1
	i = 1
	prev = 1
	while i < n - 1:
		if l[i] < l[i + 1]:
			cou += 1
			i += 1
		else:
			prev -= 1
			if prev == 0:
				prev = cou
				cou = 1
				level += 1
			else:
				cou += 1
			i += 1
	print(level)
	t -= 1


import sys
from array import array
from collections import deque

def input():
	return sys.stdin.buffer.readline().decode('utf-8')
t = int(input())
ans = [0] * t
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(depth, i) = (0, 1)
	(par, child) = (deque([1]), deque())
	while i < n:
		if not child:
			depth += 1
		child.append(a[i])
		i += 1
		while i < n and child[-1] < a[i]:
			child.append(a[i])
			i += 1
		par.popleft()
		if not par:
			(par, child) = (child, deque())
	ans[_] = depth
print(*ans, sep='\n')


t = int(input())
for q in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	depth = 1
	count = 0
	prev_count = 0
	for i in range(1, n):
		if a[i] < a[i - 1] and (not prev_count):
			depth += 1
			prev_count = count
		elif a[i] < a[i - 1] and prev_count:
			prev_count -= 1
		elif i != 1:
			count += 1
	print(depth)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	levels = [0] * n
	index = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			index += 1
		levels[i] = levels[index] + 1
	print(levels[-1])


import sys
from collections import deque
input = sys.stdin.readline

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	que = deque(arr[1:])
	q = deque([0])
	ans = 0
	while q:
		ans = q.popleft()
		prev = 0
		while que and que[0] >= prev:
			prev = que.popleft()
			q.append(ans + 1)
	return ans
for _ in range(int(input())):
	print(main())


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	ans = 0
	cur = 0
	pcur = 0
	for i in range(1, n):
		if l[i] < l[i - 1]:
			if pcur == 0:
				pcur = cur
				ans += 1
				continue
			pcur -= 1
		else:
			if i == 1:
				continue
			cur += 1
	print(ans + 1)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for i in range(t):
	(n,) = I()
	l = I()
	pr = 1
	an = 1
	i = 1
	tot = 1
	while i < n - 1:
		ct = 0
		while i < n - 1 and pr:
			if l[i] > l[i + 1]:
				pr -= 1
			ct += 1
			i += 1
		tot += ct
		if pr:
			break
		pr = ct
		an += 1
	print(an)


import sys, os
import heapq, functools, collections, bisect
import math, random
from collections import Counter, defaultdict

def solve_(lst):
	lst = lst[1:] + [10 ** 6]
	segments = []
	cur = [lst[0]]
	for (a, b) in zip(lst, lst[1:]):
		if a > b:
			segments.append(cur)
			cur = []
		cur.append(b)
	cur.pop()
	segments.append(cur)
	segments = segments[::-1]
	console(segments)
	breadth = 1
	depth = 0
	while segments:
		depth += 1
		currow = 0
		for i in range(breadth):
			if not segments:
				break
			currow += len(segments.pop())
		console(currow)
		breadth = currow
	return depth

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	pass
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def console(*args):
		pass

def solve(*args):
	console('----- solving ------')
	console(*args)
	console('----- ------- ------')
	return solve_(*args)
if True:
	inp = iter(sys.stdin.buffer.readlines())
	input = lambda : next(inp)
else:
	input = sys.stdin.buffer.readline
for case_num in range(int(input())):
	k = int(input())
	lst = list(map(int, input().split()))
	res = solve(lst)
	print(res)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf
from itertools import permutations
from copy import deepcopy
from heapq import *
from sys import setrecursionlimit

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		(l, i) = ([], 0)
		while i < n:
			j = i
			while j < n - 1 and a[j] < a[j + 1]:
				j += 1
			l.append(j - i + 1)
			i = j + 1
		(m, i, h, su, t) = (len(l), 1, 1, l[0] - 1, 0)
		while i < m:
			while i < m and su:
				t += l[i]
				su -= 1
				i += 1
			su = t
			t = 0
			h += 1
		print(h)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for x in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	c = 1
	a = 0
	t = 0
	k = 0
	for i in range(1, n):
		if m[i] < m[i - 1]:
			c -= 1
			t += k
			k = 0
			if c == 0:
				c = t
				a += 1
				t = 0
		k += 1
	print(a + 1)