You are given an array $a$ of length $n$.

Let's define the eversion operation. Let $x = a_n$. Then array $a$ is partitioned into two parts: left and right. The left part contains the elements of $a$ that are not greater than $x$ ($\le x$). The right part contains the elements of $a$ that are strictly greater than $x$ ($> x$). The order of elements in each part is kept the same as before the operation, i. e. the partition is stable. Then the array is replaced with the concatenation of the left and the right parts.

For example, if the array $a$ is $[2, 4, 1, 5, 3]$, the eversion goes like this: $[2, 4, 1, 5, 3] \to [2, 1, 3], [4, 5] \to [2, 1, 3, 4, 5]$.

We start with the array $a$ and perform eversions on this array. We can prove that after several eversions the array $a$ stops changing. Output the minimum number $k$ such that the array stops changing after $k$ eversions.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). Description of the test cases follows.

The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case print a single integer $k$ — the number of eversions after which the array stops changing.


-----Examples-----

Input
3
5
2 4 1 5 3
5
5 3 2 4 1
4
1 1 1 1
Output
1
2
0


-----Note-----

Consider the fist example.

The first eversion: $a = [1, 4, 2, 5, 3]$, $x = 3$. $[2, 4, 1, 5, 3] \to [2, 1, 3], [4, 5] \to [2, 1, 3, 4, 5]$.

The second and following eversions: $a = [2, 1, 3, 4, 5]$, $x = 5$. $[2, 1, 3, 4, 5] \to [2, 1, 3, 4, 5], [] \to [2, 1, 3, 4, 5]$. This eversion does not change the array, so the answer is $1$.

Consider the second example.

The first eversion: $a = [5, 3, 2, 4, 1]$, $x = 1$. $[5, 3, 2, 4, 1] \to [1], [5, 3, 2, 4] \to [1, 5, 3, 2, 4]$.

The second eversion: $a = [1, 5, 3, 2, 4]$, $x = 4$. $[1, 5, 3, 2, 4] \to [1, 3, 2, 4], [5] \to [1, 3, 2, 4, 5]$.

The third and following eversions: $a = [1, 3, 2, 4, 5]$, $x = 5$. $[1, 3, 2, 4, 5] \to [1, 3, 2, 4, 5], [] \to [1, 3, 2, 4, 5]$. This eversion does not change the array, so the answer is $2$.

Difficulty: EASY
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
import sys

def _hy_anon_var_2(*_hyx_GXUffffX2):

	def solution(arr):
		max_elt = 0
		steps = -1
		for x in reversed(arr):
			if x > max_elt:
				steps += 1
				max_elt = x
				_hy_anon_var_1 = None
			else:
				_hy_anon_var_1 = None
		return steps
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		print(solution(arr))
_hyx_GXUffffX1 = _hy_anon_var_2(*sys.argv)
_hy_anon_var_3 = sys.exit(_hyx_GXUffffX1) if isinstance(_hyx_GXUffffX1, int) else None


def solution(arr):
	max_elt = 0
	steps = -1
	for x in reversed(arr):
		if x > max_elt:
			steps += 1
			max_elt = x
			_hy_anon_var_1 = None
		else:
			_hy_anon_var_1 = None
	return steps
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solution(arr))


def solve():
	num = int(input())
	mas = list(map(int, input().split()))
	count = 0
	max = mas[-1]
	for i in range(num - 1, -1, -1):
		element = mas[i]
		if element > max:
			max = element
			count += 1
	return count
count_of_data = int(input())
for i in range(count_of_data):
	print(solve())


from sys import stdin, stdout

def main():
	for _ in range(int(stdin.readline().strip())):
		n = int(stdin.readline().strip())
		a = list(map(int, stdin.readline().split()))
		c = a[-1]
		r = 0
		for i in a[::-1]:
			if i > c:
				c = i
				r += 1
		print(r)
main()


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		(res, old) = (0, a[-1])
		for i in range(n - 2, -1, -1):
			if a[i] > old:
				old = a[i]
				res += 1
		print(res)
main()


def mass_counter(l):
	times = 0
	max_number = l[-1]
	for i in range(len(l) - 2, -1, -1):
		if l[i] > max_number:
			max_number = l[i]
			times += 1
	return times
for _ in range(int(input())):
	_ = input()
	print(mass_counter(list(map(int, input().split()))))


def count(kol):
	lenmas = int(input())
	chisla = list(map(int, input().split()))
	next = -1
	count = -1
	for i in range(lenmas - 1, -1, -1):
		if next < chisla[i]:
			next = chisla[i]
			count = count + 1
		else:
			pass
	print(count)
kol = int(input())
for i in range(kol):
	count(kol)


def solve():
	n = int(input())
	arr = list(map(int, input().split()))[::-1]
	cnt = 0
	mx = arr[0]
	for i in range(1, n):
		if arr[i] > mx:
			mx = arr[i]
			cnt += 1
	return cnt
for _ in range(int(input())):
	print(solve())


def main():
	tests = int(input())
	for _ in range(tests):
		input()
		array = [int(x) for x in input().split()]
		print(everse_array(array))

def everse_array(arr):
	elements = iter(reversed(arr))
	eversount = 0
	curax = next(elements)
	for el in elements:
		if el > curax:
			curax = el
			eversount += 1
	return eversount
main()


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


def solve(n, arr):
	maxValue = max(arr)
	curr = arr[-1]
	if maxValue == curr:
		print(0)
		return
	count = 1
	idx = n - 1
	while arr[idx] < maxValue:
		if arr[idx] > curr:
			curr = arr[idx]
			count += 1
		idx -= 1
	print(count)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	solve(n, arr)


for _ in range(int(input())):
	e = int(input())
	nums = list(map(int, input().split()))
	nums.reverse()
	max = 0
	counter = -1
	for i in nums:
		if i > max:
			max = i
			counter += 1
	print(counter)


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	max = 0
	count = 0
	for i in arr[::-1]:
		if i > max:
			max = i
			count += 1
	print(count - 1)
	t -= 1


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	lst = a[n - 1]
	cnt = 0
	for i in range(n - 2, -1, -1):
		if lst < a[i]:
			lst = a[i]
			cnt += 1
	print(cnt)
t = int(input())
for i in range(t):
	solve()


for s in [*open(0)][2::2]:
	r = -1
	m = 0
	for x in map(int, s.split()[::-1]):
		if x > m:
			r += 1
			m = x
	print(r)


import math

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	mx = 0
	count = -1
	for i in l[::-1]:
		if i > mx:
			mx = i
			count += 1
	print(count)
n = int(input())
for _ in range(n):
	solve()


def solve(n, a):
	count = 0
	cur = a[-1]
	for (i, num) in enumerate(a[::-1]):
		if num > cur:
			count += 1
			cur = num
	return count
ans = []
for _ in range(int(input())):
	ans.append(solve(int(input()), list(map(int, input().split()))))
print(*ans, sep='\n')


t = int(input())
for i in range(t):
	n = int(input())
	data = list(map(int, input().split()))
	num = data[-1]
	cur_max = num
	count = 0
	for k in data[::-1]:
		if k > cur_max:
			count += 1
			cur_max = k
	print(count)


import math

def modInverse(p, q):
	mod = 998244353
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p

def answer(x, y, li):
	s = []
	for p in range(0, len(li) - 1):
		s.append(li[p + 1] - li[p])
	s.append(int(1e+18))

	def solu(s, fi, y):
		m = 0
		for j in range(0, len(s)):
			m = m + min(s[j], fi)
		return m >= y
	low = 1
	high = int(1e+18)
	ans = 0
	while low < high:
		fi = (low + high) // 2
		if solu(s, fi, y):
			high = fi
			ans = fi
		else:
			low = fi + 1
	return ans
t = int(input())
for i in range(0, t):
	x = int(input())
	s = input()
	r = -1
	m = 0
	for x in map(int, s.split()[::-1]):
		if x > m:
			r += 1
			m = x
	print(r)


from collections import Counter
from itertools import accumulate, product
import operator
import math

def solve():
	n = int(input())
	A = [int(char) for char in input().split()]
	MAX = max(A)
	if A[-1] == MAX:
		return 0
	(k, prev) = (1, A[-1])
	for i in range(n - 2, -1, -1):
		num = A[i]
		if num == MAX:
			break
		if num > prev:
			prev = num
			k += 1
	return k
for _ in range(int(input())):
	print(solve())


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


import collections

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

def readInt():
	return int(input())

def readString():
	return input()

def tcase():
	t = readInt()
	for _ in range(t):
		solve()

def solve():
	n = readInt()
	arr = readLine()
	m = -1
	k = 0
	for i in range(n - 1, -1, -1):
		if arr[i] > m:
			m = arr[i]
			k += 1
	print(k - 1)
tcase()


import math

def test():
	n = count = -1
	mx = mx1 = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] > mx:
			mx = a[i]
	for i in range(n - 1, -1, -1):
		if a[i] > mx1:
			mx1 = a[i]
			count += 1
	print(count)
t = int(input())
for i in range(t):
	test()


def vyvorot(n, a):
	ma = max(a)
	cnt = 0
	k = a[len(a) - 1]
	for i in range(len(a) - 1, -1, -1):
		if a[i] > k:
			cnt += 1
			k = a[i]
	return cnt
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(vyvorot(n, a))


def solve(a) -> int:
	if len(a) == 1:
		return 0
	res = 0
	cur = a[-1]
	for i in range(len(a) - 1, -1, -1):
		if a[i] > cur:
			cur = a[i]
			res += 1
	return res
for _ in range(int(input())):
	_ = input()
	print(solve([int(i) for i in input().split()]))


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for i in range(t):
		n = int(stdin.readline())
		save = list(map(int, stdin.readline().split()))
		(ind, m) = (0, 0)
		check = 0
		count = 0
		for k in range(len(save)):
			if save[k] >= m:
				ind = k
				m = save[k]
		save = save[ind + 1:]
		save = save[::-1]
		for j in range(len(save)):
			if save[j] > check:
				count += 1
				check = save[j]
		print(count)
main()


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


def counter():
	n = int(input())
	nums = list(map(int, input().split()))
	cur = -1
	cnt = -1
	for i in range(n - 1, -1, -1):
		if cur < nums[i]:
			cnt += 1
			cur = nums[i]
	print(cnt)
t = int(input())
for i in range(t):
	counter()


def main():
	n = int(input())
	arr = list(map(int, input().split()))[::-1]
	comp = int()
	k = 0
	for i in range(n):
		if i == 0:
			comp = arr[i]
		elif arr[i] > comp:
			comp = arr[i]
			k += 1
	print(k)
for _ in range(int(input())):
	main()


t = int(input())
for k in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	max = l[-1]
	for i in range(len(l) - 1, -1, -1):
		if l[i] > max:
			max = l[i]
			count += 1
	print(count)


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


def main():
	m = int(input())
	for i in range(m):
		n = int(input())
		l = list(map(int, input().split()))
		max = 0
		max_i = 0
		for j in range(n):
			if l[j] > max:
				max = l[j]
				max_i = j
		mes_m = l[-1]
		count = 0
		for j in range(n - 1, max_i - 1, -1):
			if l[j] > mes_m:
				mes_m = l[j]
				count += 1
		print(count)
main()


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


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


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	res = last = 0
	for i in arr[::-1]:
		if last < i:
			res += 1
			last = i
	print(res - 1)


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


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	maxE = 0
	maxV = a[len(a) - 1]
	for c in range(len(a) - 1, -1, -1):
		if a[c] > maxV:
			maxE += 1
			maxV = a[c]
	print(maxE)


def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	d = max(a)
	x = a[-1]
	ans = 0
	for i in range(n - 2, -1, -1):
		if a[i] > x:
			ans += 1
			x = a[i]
		if a[i] == d:
			break
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	count = -1
	last_cut = 0
	for el in reversed(a):
		if el > last_cut:
			count += 1
			last_cut = el
	print(count)


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


t = int(input())
for ns in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	s = s[::-1]
	ans = 0
	mx = max(s)
	help = s[0]
	for i in s:
		if i > help:
			help = i
			ans += 1
		if help == mx:
			break
	print(ans)


from math import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = li()[::-1]
		c = 0
		m = max(a)
		t = a[0]
		for i in range(n):
			if a[i] > t:
				t = a[i]
				c += 1
			elif t == m:
				break
		print(c)
solve()


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


for _ in range(int(input())):
	n = int(input())
	alist = list(map(int, input().split()))
	(el, quantity) = (alist[n - 1], 0)
	for i in range(n - 2, -1, -1):
		if alist[i] > el:
			quantity += 1
			el = alist[i]
	print(quantity)


for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	im = n - list(reversed(s)).index(max(s)) - 1
	po = s[-1]
	k = 0
	for i in range(n - 2, im - 1, -1):
		if s[i] > po:
			k += 1
			po = s[i]
	print(k)


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	mx = A[n - 1]
	k = 0
	for i in range(n - 1, -1, -1):
		if A[i] > mx:
			k += 1
			mx = A[i]
	print(k)


for _ in range(int(input())):
	n = int(input())
	nums = [int(el) for el in input().split()[::-1]]
	k = 0
	x = nums[0]
	for el in nums:
		if el > x:
			x = el
			k += 1
	print(k)


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


t = int(input())
for i in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	ind = m.index(max(m))
	t = 0
	new_max = max(m)
	flag = True
	maxim = m[-1]
	for elem in m[::-1]:
		if elem > maxim:
			maxim = elem
			t += 1
	print(t)


n = int(input())
for i in range(n):
	m = int(input())
	s = list(map(int, input().split()))
	ans = 0
	x = s[-1]
	m = max(s)
	for j in s[::-1]:
		if j > x:
			x = j
			ans += 1
		if j == m:
			print(ans)
			break


t = int(input())
all = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	counter = 0
	an = a[-1]
	for i in range(n - 1, -1, -1):
		if a[i] > an:
			counter += 1
			an = a[i]
	all.append(counter)
for el in all:
	print(el)


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


def lastmax(n, lst):
	m = lst[-1]
	a = 0
	for i in range(n - 1, -1, -1):
		if lst[i] > m:
			a += 1
			m = lst[i]
	return a
for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(lastmax(n, lst))


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()][::-1]
	f = max(a)
	ans = 0
	now = a[0]
	for i in a:
		if i > now:
			ans += 1
			now = i
		if i == f:
			break
	print(ans)


t = int(input())
for r in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	m = A[n - 1]
	r = 0
	for i in range(n - 2, -1, -1):
		if A[i] > m:
			m = A[i]
			r += 1
	print(r)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	count = 0
	last = arr[-1]
	for i in range(n - 1, -1, -1):
		if arr[i] > last:
			count += 1
			last = arr[i]
	print(count)


def solve():
	n = int(input())
	a = list(input().split())
	dem = 0
	for i in range(n):
		a[i] = int(a[i])
	ma = a[n - 1]
	for i in range(n - 2, -1, -1):
		if a[i] > ma:
			dem += 1
			ma = a[i]
	print(dem)
for i in range(int(input())):
	solve()


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


import sys

def solve(arr):
	mx = max(arr)
	ans = 1
	i = 0
	last = arr[-1]
	if arr[-1] == mx:
		return 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == mx:
			return ans
		if arr[i] > last:
			ans += 1
			last = arr[i]
	return ans
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, sys.stdin.readline().strip().split()))
	print(solve(arr))


for _ in range(int(input())):
	x = int(input())
	array = list(map(int, input().split()))
	great = max(array)
	array = list(reversed(array))
	ans = 0
	temp = array[0]
	for i in array:
		if i > temp and temp != great:
			ans += 1
			temp = i
	print(ans)


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


tt = int(input())
for TT in range(tt):
	n = int(input())
	a = [int(i) for i in input().split()]
	mx = a[-1]
	cnt = 0
	for x in reversed(a):
		if x > mx:
			mx = x
			cnt += 1
	print(cnt)


cases = int(input())
for i in range(cases):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	max = arr[n - 1]
	for (i, item) in enumerate(reversed(arr)):
		if item > max:
			max = item
			count += 1
	print(count)


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


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


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	count = 0
	ms = a[-1]
	for j in range(len(a) - 1, -1, -1):
		if a[j] > ms:
			count += 1
			ms = a[j]
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	m = a[-1]
	k = 0
	for i in range(n - 2, -1, -1):
		if a[i] > m:
			k += 1
			m = a[i]
	print(k)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	MAX = max(arr)
	count = 0
	cur = arr[-1]
	if cur == MAX:
		print(count)
	else:
		for i in range(n - 2, -1, -1):
			if arr[i] > cur:
				cur = arr[i]
				count += 1
		print(count)


from sys import stdin, stdout
import math
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	cnt = 0
	mx = a[-1]
	for i in range(n - 2, -1, -1):
		if a[i] > mx:
			mx = a[i]
			cnt += 1
	print(cnt)


for s in [*open(0)][2::2]:
	a = [*map(int, s.split())]
	c = ans = 0
	for x in a[::-1]:
		if x > c:
			c = x
			ans += 1
	print(ans - 1)


t = int(input())
while t:
	n = int(input())
	mas = list(map(int, input().split()))
	ans = 0
	mx = mas[-1]
	for i in range(n - 2, -1, -1):
		if mas[i] > mx:
			mx = mas[i]
			ans += 1
	print(ans)
	t -= 1


m = int(input())
for i in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	max = a[-1]
	k = 0
	for i in range(n - 2, -1, -1):
		if a[i] > max:
			k += 1
			max = a[i]
	print(k)


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


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


def arrayEversion(n, array):
	m = max(array)
	max_index = 0
	for x in reversed(range(n)):
		if array[x] == m:
			max_index = x
			break
	if m == array[-1]:
		return 0
	if m == array[-2]:
		return 1
	else:
		prev = array[-1]
		c = 0
		for x in reversed(range(max_index, n - 1)):
			if array[x] > prev:
				c += 1
				prev = array[x]
		return c
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(arrayEversion(n, l))


for _ in range(int(input())):
	input()
	array = [int(i) for i in input().split()][::-1]
	(r, el, max_el) = (0, 0, max(array))
	for i in array:
		if i == max_el:
			break
		elif i > el:
			el = i
			r += 1
	print(r)


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


t = int(input())
for _ in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	maxx = max(array)
	current = array[-1]
	k = 0
	for i in range(n - 2, -1, -1):
		if array[i] > current:
			k += 1
			current = array[i]
			if current == maxx:
				break
	print(k)


t = int(input())
for t0 in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = a[::-1]
	x = b[0]
	c = 0
	for i in range(1, n):
		if b[i] > x:
			x = b[i]
			c += 1
	print(c)


for _ in range(int(input())):
	input()
	k = 0
	t = 0
	a = list(map(int, input().split()))
	m = max(a)
	for x in reversed(a):
		if x == m:
			print(k)
			break
		elif x > t:
			k += 1
			t = x


t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	mn = lst[n - 1]
	rs = 0
	for i in range(n - 1, -1, -1):
		if lst[i] > mn:
			rs += 1
			mn = lst[i]
	print(rs)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	m = max(a)
	if a[n - 1] == m:
		print(0)
	else:
		k = 0
		ele = a[n - 1]
		for i in range(n - 2, -1, -1):
			if a[i] > ele:
				k += 1
				ele = a[i]
		print(k)
	t -= 1


import sys
import bisect
inp = sys.stdin.readline

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

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(inp())):
	n = int(inp())
	a = [int(i) for i in inp().split()]
	ans = 0
	m = a[-1]
	for i in range(n - 1, -1, -1):
		if a[i] > m:
			ans += 1
			m = a[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m = max(arr)
	res = 0
	t_max = 0
	for i in range(n - 1, -1, -1):
		if arr[i] == m:
			break
		if arr[i] <= t_max:
			continue
		t_max = arr[i]
		res += 1
	print(res)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))[::-1]
	c = w[0]
	count = 0
	for i in range(1, n):
		if w[i] > c:
			c = w[i]
			count += 1
	print(count)