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 (≤ 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] → [2, 1, 3], [4, 5] → [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 ≤ t ≤ 100). Description of the test cases follows.

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5).

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).

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

Output

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

Example

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] → [2, 1, 3], [4, 5] → [2, 1, 3, 4, 5]. 
  * The second and following eversions: a = [2, 1, 3, 4, 5], x = 5. [2, 1, 3, 4, 5] → [2, 1, 3, 4, 5], [] → [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] → [1], [5, 3, 2, 4] → [1, 5, 3, 2, 4]. 
  * The second eversion: a = [1, 5, 3, 2, 4], x = 4. [1, 5, 3, 2, 4] → [1, 3, 2, 4], [5] → [1, 3, 2, 4, 5]. 
  * The third and following eversions: a = [1, 3, 2, 4, 5], x = 5. [1, 3, 2, 4, 5] → [1, 3, 2, 4, 5], [] → [1, 3, 2, 4, 5]. This eversion does not change the array, so the answer is 2.

Difficulty: EASY

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


def solve():
	N = int(input())
	A = list(map(int, input().split()))
	A = A[::-1]
	count = 0
	prev = A[0]
	for i in range(1, N):
		if A[i] > prev:
			prev = A[i]
			count += 1
	print(count)
T = int(input())
for i in range(T):
	solve()


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)


import sys, array, bisect, collections, heapq, itertools, math, functools
sys.setrecursionlimit(100000)

def _r():
	return sys.stdin.buffer.readline()

def rs():
	return _r().decode('ascii').strip()

def rn():
	return int(_r())

def rnt():
	return tuple(map(int, _r().split()))

def rnl():
	return list(rnt())

def rna():
	return array.array('q', rnt())

def pnl(l):
	print(' '.join(map(str, l)))

def solve(n, a):
	sol = 0
	m = a[-1]
	for i in range(n - 2, -1, -1):
		if a[i] > m:
			sol += 1
			m = a[i]
	return sol
for _ in range(rn()):
	n = rn()
	a = rnl()
	print(solve(n, a))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mn = max(a)
	count = 0
	curr = n - 1
	prev = -1
	while a[curr] != mn:
		if prev == -1 or a[curr] > a[prev]:
			count += 1
			prev = curr
		curr -= 1
	print(count)


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


import math
import math as m

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

def I():
	return int(input())

def M():
	return map(int, input().split())
from math import sqrt
from itertools import count, islice

def is_prime(n):
	return n > 1 and all((n % i for i in islice(count(2), int(sqrt(n) - 1))))

def solve():
	n = I()
	arr = L()
	nowval = -1
	res = 0
	maxi = max(arr)
	if arr[-1] == maxi:
		print(0)
		return
	nowval = arr[-1]
	res = 1
	for i in range(n - 1, -1, -1):
		if arr[i] == maxi:
			print(res)
			return
		if arr[i] > nowval:
			res += 1
			nowval = arr[i]
	print(res)
for _ in range(I()):
	solve()


from sys import stdin
for testcase in range(int(stdin.readline())):
	length = int(stdin.readline())
	values = list(map(int, stdin.readline().split()))
	minimum_eversions = 0
	currentEnd = values[-1]
	for index in range(length - 2, -1, -1):
		if values[index] > currentEnd:
			currentEnd = values[index]
			minimum_eversions += 1
	print(minimum_eversions)


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)


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

def get():
	return int(input())

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

def S():
	for test in range(int(input())):
		solve()
import math
import itertools as it
import bisect
import time
import collections as ct

def lower_bound(a, x):
	l = -1
	r = len(a)
	while l + 1 != r:
		mid = l + r >> 1
		if a[mid] < x:
			l = mid
		else:
			r = mid
	return r

def upper_bound(a, x):
	l = -1
	r = len(a)
	while l + 1 != r:
		mid = l + r >> 1
		if a[mid] <= x:
			l = mid
		else:
			r = mid
	return r

def solve():
	n = get()
	a = getint()
	ans = 0
	cnt = a[-1]
	for i in range(n - 1, -1, -1):
		if cnt < a[i]:
			ans += 1
			cnt = a[i]
	print(ans)
S()


for _ in range(int(input())):
	p = int(input())
	y = list(map(int, input().split()))
	cnt = 1
	g = max(y)
	if p == 1 or y[p - 1] == g:
		print(0)
	else:
		tp = y[p - 1]
		for i in range(p - 2, -1, -1):
			if y[i] == g:
				break
			if y[i] > tp:
				cnt += 1
			tp = max(tp, y[i])
		print(cnt)


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
ceil_div = lambda a, b: -(-a // b)
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	ans = 0
	m = -1
	ma = max(a)
	while a:
		if a[-1] == ma:
			break
		if a[-1] > m:
			ans += 1
			m = a[-1]
		a.pop()
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mmax = max(arr)
	i = n - 2
	cur = arr[-1]
	if cur == mmax:
		print(0)
		continue
	step = 1
	while arr[i] != mmax:
		if arr[i] > cur:
			step += 1
			cur = arr[i]
		i -= 1
	print(step)


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)


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


for _ in range(int(input())):
	n = int(input())
	lst = [int(x) for x in input().split()]
	ans = 0
	maxi = max(lst)
	if maxi == lst[n - 1]:
		print(0)
	else:
		x = lst[n - 1]
		ans += 1
		for i in range(n - 2, -1, -1):
			if lst[i] > x:
				x = lst[i]
				if x == maxi:
					print(ans)
					break
				ans += 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	last = a[-1]
	mx = max(a)
	mn = 0
	k = 0
	for i in range(len(a) - 1, -1, -1):
		if a[i] < mx and a[i] > mn:
			k += 1
			mn = a[i]
		if a[i] == mx:
			break
	print(k)


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


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)


t = int(input())
for asdfghjklbvcljfskdjfdlsfjsdlfjslfj in range(t):
	input()
	arrrrrrrray = list(map(int, input().split()))
	x = arrrrrrrray[len(arrrrrrrray) - 1]
	ans = 0
	for i in range(len(arrrrrrrray) - 2, -1, -1):
		if arrrrrrrray[i] > x:
			ans += 1
			x = arrrrrrrray[i]
	print(ans)


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()


t = int(input())
while t > 0:
	a = int(input())
	l = list(map(int, input().split()))
	k = l[len(l) - 1]
	cnt = 0
	i = len(l) - 1
	while i >= 0:
		if l[i] > k:
			cnt += 1
			k = l[i]
		i -= 1
	print(cnt)
	t -= 1


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

def inp():
	l = list(map(int, input().split()))
	return l
for _ in range(int(input())):
	(n,) = inp()
	l = inp()
	s = 0
	x = l[-1]
	for i in range(n - 2, -1, -1):
		if l[i] > x:
			s += 1
			x = l[i]
	print(s)


from sys import stdout, stdin
from io import IOBase, BytesIO
from os import read, supports_follow_symlinks, write, fstat
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 = read(self._fd, max(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, size: int=...):
		while self.newlines == 0:
			b = read(self._fd, max(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:
			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', 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()
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

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

def unioun_max_min(arr1, arr2):
	len1 = len(arr1)
	len2 = len(arr2)
	result = []
	if len1 > len2:
		for i in range(len2):
			result.append(arr1[i])
			result.append(arr2[i])
		result.append(arr1[len1 - 1])
	elif len1 == len2:
		for i in range(len2):
			result.append(arr1[i])
			result.append(arr2[i])
	else:
		for i in range(len1):
			result.append(arr2[i])
			result.append(arr1[i])
		result.append(arr2[len2 - 1])
	return result

def main():
	t = int(input())
	for _ in ' ' * t:
		n = int(input())
		arr = list(map(int, input().split()))
		begin = arr[-1]
		ans = 0
		for i in arr[::-1]:
			if i > begin:
				ans += 1
				begin = i
		print(ans)
main()


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	n = ii()
	a = il()
	ans = 0
	x = max(a)
	i = n - 1
	while i >= 0:
		if a[i] == x:
			break
		ans += 1
		j = i
		i -= 1
		while i >= 0:
			if a[i] > a[j]:
				break
			i -= 1
	print(ans)


from collections import Counter, deque
import math
from random import randint
from bisect import bisect
import sys
import re
import copy
from decimal import Decimal, getcontext
getcontext().prec = 32
MOD = 1000000007
MAX = sys.maxsize
MIN = -sys.maxsize
prime = []

class get:

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

	def str():
		return input().split()

	def float():
		return list(map(float, input().split()))

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

def sqrt(x):
	return int(math.sqrt(x)) + 1

def gcd(*args):
	result = args[0]
	for item in args:
		result = math.gcd(result, item)
	return result

def LCM(a, b):
	return a * b // math.gcd(a, b)

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

def solve():
	n = int(input())
	a = get.int()
	if a[-1] == max(a):
		print(0)
		return
	max_ = MIN
	j = 0
	for i in range(n - 1, -1, -1):
		if a[i] > max_:
			max_ = a[i]
			j = i
	r_max = MIN
	res = 0
	for i in range(n - 1, j, -1):
		if a[i] > r_max:
			r_max = a[i]
			res += 1
	print(res)
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	eversions = 0
	cur = a[n - 1]
	counter = n - 2
	while counter != -1:
		if a[counter] > cur:
			cur = a[counter]
			eversions += 1
		counter -= 1
	print(eversions)


t = int(input())
for te in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	maxi = max(a)
	count = 0
	if a[-1] == maxi:
		print(count)
	else:
		count = 0
		maxb = a[-1]
		for i in range(n - 2, -1, -1):
			if a[i] > maxb:
				maxb = a[i]
				count += 1
		print(count)


import sys

def solve(n, arr):
	answer = 0
	maxi = float('-inf')
	max_index = -1
	for i in range(n):
		if arr[i] >= maxi:
			maxi = arr[i]
			max_index = i
	i = n - 2
	current = arr[n - 1]
	if current != maxi:
		answer += 1
	while i > max_index:
		if arr[i] > current:
			answer += 1
			current = arr[i]
		i -= 1
	return answer

def main():
	test_case = int(sys.stdin.readline())
	for tc in range(test_case):
		n = int(sys.stdin.readline())
		arr = [int(a) for a in sys.stdin.readline().split()]
		print(solve(n, arr))
main()


def max1(a):
	maxi = 0
	for i in range(len(a)):
		if a[i] >= a[maxi]:
			maxi = i
	return maxi
for i in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	maxi = max1(a)
	(ans, ele) = (0, 0)
	if a[n - 1] != a[maxi]:
		ele = n - 1
		ans += 1
	else:
		print('0')
		continue
	for j in range(n - 2, maxi, -1):
		if a[j] > a[ele]:
			ele = j
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	ans = 0
	m = max(li)
	if li[n - 1] != m:
		ans = ans + 1
	for i in range(n - 2, 0, -1):
		if li[i] > li[i + 1]:
			if li[i] == m:
				break
			else:
				ans = ans + 1
		else:
			(li[i], li[i + 1]) = (li[i + 1], li[i])
	print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, functools, copy, random
from functools import reduce
import operator
inf = float('inf')
mod = 10 ** 9 + 7

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def LS():
	return input().split()

def endl():
	return print('\n')

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

def grayCode(n):
	return n ^ n >> 1
sys.setrecursionlimit(20000)
graph = collections.defaultdict(list)
grid = []
visited = set()
ways = ['D', 'U', 'R', 'L']
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

def find(i):
	if par[i] != i:
		par[i] = find(par[i])
	return par[i]

def union(a, b):
	a = find(a)
	b = find(b)
	if a == b:
		return False
	par[a] = b
	return True

def initGraph(m):
	for _ in range(m):
		(u, v) = LI()
		graph[u - 1].append(v - 1)
		graph[v - 1].append(u - 1)
	return graph

def initGraphW(m):
	for _ in range(m):
		(a, b, c) = LI()
		graph[a - 1].append((b - 1, c))
		graph[b - 1].append((a - 1, c))

def initGrid(h, w):
	for i in range(h):
		s = S()
		grid.append(list(s))
	return grid

def soe(limit):
	a = [True] * limit
	a[0] = a[1] = False
	for (i, isprime) in enumerate(a):
		if isprime:
			yield i
			for n in range(i * i, limit, i):
				a[n] = False
	return a
for _ in range(I()):
	n = I()
	a = LI()
	mx = max(a)
	if a[-1] == mx:
		print(0)
		continue
	cnt = 1
	temp = a[-1]
	for i in reversed(range(n - 1)):
		if a[i] == mx:
			break
		if a[i] > temp:
			temp = a[i]
			cnt += 1
	print(cnt)


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


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


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


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	prev = n - 1
	cur = n - 2
	count = 0
	while cur >= 0:
		if a[prev] < a[cur]:
			count += 1
			prev = cur
		cur -= 1
	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)


import bisect
mod = 10 ** 9 + 7
eps = 10 ** (-9)

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

def __lcm(a, b):
	return a * b / __gcd(a, b)

def __fact(n):
	return 1 if n == 1 else n * __fact(n - 1)

def __mex(a):
	mex = 0
	a.sort()
	for x in a:
		if x <= mex:
			mex += 1
		else:
			break
	return mex

def __dist(x1, y1, x2, y2):
	return (x1 - x2) ** 2 + (y1 - y2) ** 2

def __getprimes(n):
	isprime = [True for i in range(n + 1)]
	primes = []
	for i in range(2, n + 1):
		if isprime[i]:
			for j in range(i * i, n + 1, i):
				isprime[j] = False
	for i in range(2, n + 1):
		if isprime[i]:
			primes.append(i)
	return primes

def __modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

def __isprime(n):
	if n < 2:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def __cntprimediv(n):
	ret = 0
	x = n
	i = 2
	while i * i <= x:
		while n % i == 0:
			n //= i
			ret += 1
		i += 1
	if n > 1:
		ret += 1
	return ret

def __primefactors(n):
	ret = []
	x = n
	i = 2
	while i * i <= x:
		while n % i == 0:
			ret.append(i)
			n //= i
		i += 1
	if n > 1:
		ret.append(n)
	return ret

def __sumdigit(n):
	ret = 0
	while n > 0:
		ret += n % 10
		n //= 10
	return ret

def __zfunc(s):
	n = len(s)
	z = [0 for i in range(n)]
	l = 0
	r = 0
	for i in range(1, n):
		if r >= i:
			z[i] = min(z[i - l], r - i + 1)
		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
			z[i] += 1
		if i + z[i] - 1 > r:
			l = i
			r = i + z[i] - 1
	return z

def __to(n, x):
	ret = ''
	while n > 0:
		q = n % x
		if q < 10:
			ret += str(q)
		else:
			ret += chr(q - 10 + ord('a'))
		n //= x
	return ret[::-1]

def solve(t):
	n = int(input())
	a = list(map(int, input().split()))
	mx = max(a)
	last = a[-1]
	ans = 1
	for i in range(n - 1, -1, -1):
		if a[i] == mx:
			break
		elif a[i] > last:
			ans += 1
			last = a[i]
	if a[-1] == mx:
		ans = 0
	print(ans)
t = 1
t = int(input())
for i in range(t):
	solve(i + 1)


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()


for t in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	count = 0
	curr = A[-1]
	maxx = max(A)
	for i in range(N - 1, -1, -1):
		if A[i] > curr:
			count += 1
			curr = A[i]
		if A[i] == maxx:
			break
	print(count)


import bisect
import collections
import itertools
import sys
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()

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

def lli(rows):
	return [li() for _ in range(rows)]

def si():
	return input()

def ii():
	return int(input())

def ins():
	return input().split()

def drank(d, processing, da, rank):
	tmp = 10 ** 9
	if len(d[da]) == 1:
		return 1
	for di in d[da]:
		if processing[di - 1] == 0:
			processing[di - 1] = 1
			tmp = min(tmp, drank(d, processing, di, rank))
			processing[di - 1] = 0
	rank[da - 1] = tmp + 1
	return tmp + 1

def binary_search(n, a):
	l = len(a)
	low = 0
	high = l - 1
	while high >= low:
		mid = (high + low) // 2
		if a[mid] == n:
			return mid
		elif a[mid] > n:
			high = mid - 1
		else:
			low = mid + 1
	return -1
is_prime = [True] * (10 ** 6 + 1)

def primeseive(n):
	is_prime[0] = is_prime[1] = False
	i = 2
	while i * i <= n:
		if is_prime[i] == True:
			for j in range(i * i, n + 1, i):
				is_prime[j] = False
		i += 1

def solve():
	n = ii()
	a = li()
	a = a[::-1]
	ans = 0
	m = a[0]
	for i in range(1, n):
		if a[i] > m:
			ans += 1
			m = a[i]
	return ans

def main():
	for _ in range(II()):
		sys.stdout.write(str(solve()) + '\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	steps = 0
	prev = 1
	j = prev
	while j <= len(A):
		j += 1
		while j <= len(A) and A[-j] <= A[-prev]:
			j += 1
		if j > len(A):
			break
		else:
			prev = j
			steps += 1
	print(steps)


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()


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


import os
import sys
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heapify, heappop, heappush, nlargest, nsmallest
from io import BytesIO, IOBase
from math import inf, sqrt
from types import GeneratorType
BUFSIZE: int = 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()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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

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

def modInverse(a, m):
	g = gcd(a, m)
	if g != 1:
		return -1
	else:
		return power(a, m - 2, m)

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m

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

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	ans = set()
	for p in range(2, n + 1):
		if prime[p]:
			ans.add(p)
	return ans
MOD = 1000000007
INT_MAX = inf
INT_MIN = -inf

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		idxmax = -1
		maxval = -1
		for i in range(n):
			if a[i] >= maxval:
				maxval = a[i]
				idxmax = i
		if idxmax == n - 1:
			print(0)
		else:
			count = 1
			max = a[n - 1]
			for i in range(n - 2, idxmax, -1):
				if a[i] > max:
					max = a[i]
					count += 1
			print(count)
main()


from sys import stdin

def read_input():
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	return (n, a)

def solve(n, a):
	answer = 0
	running_max = a[-1]
	for ai in a[::-1]:
		if ai > running_max:
			answer += 1
			running_max = ai
	return answer

def main():
	t = int(stdin.readline())
	for _ in range(t):
		input = read_input()
		answer = solve(*input)
		print(answer)
main()


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))


import math, sys
from collections import defaultdict, deque
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())
		d = set()
		l1 = l
		n1 = len(l1)
		mx = max(l1)
		ans = 0
		cur_mx = -float('inf')
		for i in range(n1 - 1, -1, -1):
			if l1[i] == mx:
				break
			if cur_mx < l1[i]:
				ans += 1
				cur_mx = l1[i]
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re import *
from os import *

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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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:
			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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

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

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

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

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

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	n = getInt()
	arr = zzz()[::-1]
	mx = max(arr)
	x = arr[0]
	k = 0
	for i in arr:
		if i > x:
			k += 1
			x = i
		if i == mx:
			break
	print(k)


a = int(input())
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	t = max(z)
	cnt = 0
	maxa = 0
	for i in range(len(z) - 1, -1, -1):
		if z[i] == t:
			break
		if z[i] > maxa:
			maxa = z[i]
			cnt += 1
	print(cnt)


from sys import stdin, stdout, setrecursionlimit as srl
from threading import stack_size
from collections import deque, defaultdict as dd
from math import gcd, ceil, sqrt
from bisect import bisect_left as lb
from bisect import bisect_right as rb
flush = stdout.flush
p = int(1000000000.0 + 7)
tc = 1
tc = int(input())
for _ in range(1, tc + 1):
	n = int(input())
	m = list(map(int, input().split()))
	mx = max(m)
	cnt = 0
	curr = 0
	for i in range(n - 1, -1, -1):
		if m[i] == mx:
			print(cnt)
			break
		elif m[i] > curr:
			cnt += 1
			curr = m[i]


from collections import deque, defaultdict, Counter, OrderedDict
import math, os, sys, heapq, bisect, random
from itertools import *
from io import BytesIO, IOBase

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 inpu():
	return int(inp())
M = 1000000007

def main():
	how_much_noob_I_am = 1
	how_much_noob_I_am = inpu()
	for _ in range(how_much_noob_I_am):
		n = inpu()
		arr = lis()
		if arr[-1] == max(arr):
			print(0)
			continue
		q = arr[-1]
		p = max(arr)
		ans = 1
		for i in range(n - 1, -1, -1):
			if arr[i] == p:
				break
			if arr[i] > q:
				ans += 1
				q = arr[i]
		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()


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


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = a[::-1]
	ma = max(a)
	pre = a[0]
	ans = 0
	if ma == pre:
		print(0)
		continue
	ans = 1
	for j in range(1, n):
		if a[j] == ma:
			break
		elif a[j] <= pre:
			continue
		else:
			ans += 1
			pre = a[j]
	print(ans)


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


t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	maximum = 1
	for i in range(n):
		a[i] = int(a[i])
		if a[i] >= maximum:
			maximum = a[i]
	if a[n - 1] == maximum:
		print(0)
	else:
		k = 1
		newMax = a[n - 1]
		for j in range(n - 1, 0, -1):
			if a[j] > newMax:
				if a[j] == maximum:
					break
				k += 1
				newMax = a[j]
		print(k)


import sys
import math
import collections
import heapq
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]
r = lambda : sys.stdin.readline().rstrip()
MIS = lambda : map(int, r().split())
for _ in range(int(r())):
	N = int(r())
	L = list(MIS())
	ans = 0
	now = L[-1]
	for i in range(N - 2, -1, -1):
		if L[i] > now:
			now = L[i]
			ans += 1
	print(ans)


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	n = I()
	a = L()
	m = max(a)
	if a[-1] == m:
		print(0)
		continue
	ans = 1
	cur = a[-1]
	for i in range(n - 2, -1, -1):
		if a[i] == m:
			break
		if a[i] > cur:
			ans += 1
			cur = a[i]
	print(ans)


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial, gcd
from bisect import bisect_left, bisect_right, insort
from itertools import permutations, combinations
import sys, io, os
input = sys.stdin.readline
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
inf = float('inf')
mod = 10 ** 9 + 7

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b
t = int(input())
for i in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	counter = 0
	maxa = l[-1]
	for i in reversed(l):
		if i > maxa:
			maxa = i
			counter += 1
	print(counter)


import sys, os
import math
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase
from heapq import *
from bisect import *
from collections import *

def pge(arr):
	sta = []
	ans = [-1] * len(arr)
	for i in range(len(arr)):
		while sta and arr[sta[-1]] < arr[i]:
			ans[sta.pop()] = i
		sta.append(i)
	return ans

def main():
	for _ in range(mi()):
		n = mi()
		a = list(MI())
		a = a[::-1]
		arr = pge(a)
		x = 0
		ans = 0
		while arr[x] != -1:
			ans += 1
			x = arr[x]
		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')

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

def mi():
	return int(input())

def outP(var):
	sys.stdout.write(str(var) + '\n')
MOD = 10 ** 9 + 7
mod = 998244353
main()


import heapq
import sys
import math
from collections import deque
from bisect import bisect_left, bisect_right
I = sys.stdin.readline
II = lambda : int(I())
IN = lambda x: map(int, x.split())
FN = lambda x: map(float, x.split())
L = lambda x: list(IN(x))
M = 1000000007
P = print
T = True
F = False
for _ in range(II()):
	n = II()
	a = L(I())
	c = 0
	l = 0
	for i in range(n - 1, -1, -1):
		if a[i] > l:
			c += 1
			l = a[i]
	print(c - 1)


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


for _ in range(int(input())):
	array_length = int(input())
	array = list(map(int, input().split()))
	maximum = max(array)
	number_of_eversions = 0
	index = array_length - 1
	local_maximum = 0
	while index >= 0:
		if array[index] == maximum:
			print(number_of_eversions)
			break
		elif array[index] > local_maximum:
			local_maximum = array[index]
			number_of_eversions += 1
		index -= 1


t = int(input())
for i in range(t):
	b = int(input())
	a = list(map(int, input().strip().split()))
	maximum_1 = max(a)
	pos = b - 1
	point = 0
	while a[pos] != maximum_1:
		j = pos - 1
		while a[j] <= a[pos]:
			j = j - 1
		pos = j
		point = point + 1
	print(point)


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)


testcases = int(input())
for i in range(testcases):
	n = int(input())
	table = [int(x) for x in input().strip().split()]
	k = 0
	maxi = max(table)
	index = n - 1
	nexti = table[index]
	while maxi != nexti:
		k += 1
		while nexti >= table[index] and index > 0:
			index -= 1
		nexti = table[index]
	print(k)


for _ in range(int(input())):
	n = int(input())
	lst = [*map(int, input().split())]
	(res, curmax) = (0, lst[n - 1])
	for i in range(n - 1, -1, -1):
		if lst[i] > curmax:
			curmax = lst[i]
			res += 1
	print(res)


t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	numbers = [int(i) for i in input().strip().split()]
	last = numbers[n - 1]
	count = 0
	for index in reversed(range(n - 1)):
		if numbers[index] > last:
			count += 1
			last = numbers[index]
	print(count)


import sys
int1 = lambda x: int(x) - 1
pDB = lambda *x: print(*x, end='\n', file=sys.stderr)
p2D = lambda x: print(*x, sep='\n', end='\n\n', file=sys.stderr)

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

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

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

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
inf = 4294967295
md = 998244353

def solve():
	n = II()
	aa = LI()
	now = aa[-1]
	ans = 0
	for i in range(n - 1)[::-1]:
		if aa[i] > now:
			ans += 1
			now = aa[i]
	print(ans)
for testcase in range(II()):
	solve()


import os
import sys
from io import BytesIO, IOBase
import math
mod = 1000000007

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

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

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

def lower_bound(arr, n, k):
	start = 0
	end = n - 1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] == k:
			return mid
		elif arr[mid] > k:
			if mid > 0:
				if arr[mid - 1] < k:
					return mid - 1
			else:
				return -1
		elif mid < n - 1:
			if arr[mid + 1] > k:
				return mid
		else:
			return mid

def upper_bound(arr, n, k):
	start = 0
	end = n - 1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] == k:
			return mid
		elif arr[mid] > k:
			if mid > 0:
				if arr[mid - 1] < k:
					return mid
			else:
				return mid
		elif mid < n - 1:
			if arr[mid + 1] > k:
				return mid + 1
		else:
			return -1

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

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

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		if max(arr) == arr[-1]:
			print(0)
		else:
			maxx = 0
			for i in range(n):
				if arr[i] >= arr[maxx]:
					maxx = i
			ans = 0
			prev = 0
			for i in range(n - 1, maxx, -1):
				if arr[i] > prev:
					ans += 1
					prev = arr[i]
			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()


for _ in range(int(input())):
	(n, a) = (int(input()), list(map(int, input().split())))
	(pre, ans, ma) = (0, 0, max(a))
	for num in a[::-1]:
		if num == ma:
			break
		if num > pre:
			(pre, ans) = (num, ans + 1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	v = [int(i) for i in input().split()]
	p = max(v)
	if v[-1] == p:
		print(0)
		continue
	p1 = v[-1]
	ans = 1
	for i in range(n - 1, -1, -1):
		if v[i] <= p1:
			continue
		elif v[i] == p:
			print(ans)
			break
		else:
			p1 = v[i]
			ans += 1
	else:
		print(ans)


t = int(input())
for i in range(t):
	count = 0
	n = int(input())
	a = [int(j) for j in input().split()]
	ax = a[n - 1]
	for y in range(n - 2, -1, -1):
		if ax < a[y]:
			count += 1
			ax = a[y]
	print(count)


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)


def input_int():
	return int(input())

def input_multiple():
	return map(int, input().split())
t = input_int()
while t > 0:
	n = input_int()
	a = list(input_multiple())
	count = 0
	i = n - 1
	while i >= 0:
		j = i - 1
		while j >= 0 and a[j] <= a[i]:
			j -= 1
		if j < 0:
			break
		count += 1
		i = j
	print(count)
	t -= 1


import sys
inpu = sys.stdin.readline
prin = sys.stdout.write
t = int(inpu())
for _ in range(t):
	n = int(inpu())
	a = list(map(int, inpu().split()))
	big = max(a)
	ind = n - 1
	tot = 0
	seen = 0
	while a[ind] != big:
		if a[ind] > seen:
			seen = a[ind]
			tot += 1
		ind -= 1
	print(tot)


import sys
import math
import collections
import operator as op
import heapq as hq
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor, log
from bisect import bisect_right, bisect_left, bisect
from itertools import permutations
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def check(a, k, n):
	ans = 0
	for i in range(n - 1):
		ans += min(k, a[i + 1] - a[i])
	ans += k
	return ans
MOD = 1000000007
PMOD = 998244353
LOGN = 30
alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
N = 2 * 100005 + 1
T = 1
T = int(input())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, input().rstrip().split()))
	mx = -1
	for i in range(n):
		mx = max(a[i], mx)
	if mx == a[-1]:
		print(0)
		continue
	x = a[-1]
	ans = 0
	for i in range(n - 1, -1, -1):
		if a[i] > x:
			ans += 1
			x = a[i]
		if a[i] == mx:
			break
	print(ans)


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	maxi = max(a)
	idx = n - 1
	ans = 0
	while a[idx] != maxi:
		i = idx - 1
		while a[i] <= a[idx]:
			i = i - 1
		idx = i
		ans = ans + 1
	print(ans)


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


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	rev = a[::-1]
	amax = max(rev)
	pos = rev.index(amax)
	l = rev[:pos + 1]
	first = l[0]
	steps = 0
	for item in l:
		if item > first:
			first = item
			steps += 1
	print(steps)


from bisect import bisect_left
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mx = max(a)
	i = n - 2
	cur = a[-1]
	if cur == mx:
		print(0)
		continue
	k = 1
	while a[i] != mx:
		if a[i] > cur:
			k += 1
			cur = a[i]
		i -= 1
	print(k)


from itertools import groupby
from collections import OrderedDict
import math
from collections import Counter
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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()

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

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	n = str(n)
	return int(n, 2)
t = int(input())
for qq in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = max(l)
	l.reverse()
	c = 0
	flag = 0
	x = l[0]
	if x == a:
		print(0)
		continue
	for i in range(n):
		if l[i] > x:
			x = l[i]
			c += 1
			if x == a:
				print(c)
				flag = 1
				break
	if flag == 0:
		print(c)


cases = int(input())
for loop in range(cases):
	datalen = int(input())
	data = input().split(' ')
	for i in range(len(data)):
		data[i] = int(data[i])
	data = data[::-1]
	currmax = data[0]
	k = 0
	for d in data:
		if d > currmax:
			currmax = d
			k += 1
	print(k)


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import math
import bisect
t = int(input())
for a0 in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	z = max(l)
	ans = 0
	maxx = l[-1]
	for i in range(n - 1, -1, -1):
		if l[i] > maxx:
			ans += 1
			maxx = l[i]
	print(ans)


import sys
from collections import deque
import math
from bisect import bisect_left
from functools import cmp_to_key

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()

def FACT(n, mod):
	s = 1
	facts = [1]
	for i in range(1, n + 1):
		s *= i
		s %= mod
		facts.append(s)
	return facts[n]

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
for _ in range(II()):
	n = II()
	a = LI()
	i = n - 1
	ans = 0
	m = max(a)
	c = a[-1]
	while i >= 0:
		if a[i] > c:
			ans += 1
			c = a[i]
		i -= 1
	print(ans)


import math
import sys
import bisect
from itertools import permutations

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

def xd():
	return int(input())

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

def xx(x):
	sys.stdout.write(x)
n = xd()
for i in range(n):
	a = xd()
	arr = ll()
	count = 0
	for j in range(1, len(arr)):
		if arr[len(arr) - 1 - j] > arr[len(arr) - 1]:
			arr[len(arr) - 1] = arr[len(arr) - 1 - j]
			count += 1
	print(count)


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())
	a = list(map(int, input().split()))
	ans = a[-1]
	dem = 0
	a.reverse()
	for i in range(1, len(a)):
		if a[i] > ans:
			ans = a[i]
			dem += 1
	print(dem)


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


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x1 = a.index(max(a))
	x2 = max(a)
	c = 0
	p = a[-1]
	if p == x2:
		print(0)
	else:
		for j in range(n - 2, x1 - 1, -1):
			if p == x2:
				break
			elif a[j] > p:
				p = a[j]
				c = c + 1
		print(c)


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()


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


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


from __future__ import division, print_function
import math
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')

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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def I():
	return int(input())

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

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

def invr():
	return map(int, input().split())
import itertools
from sys import maxsize, stdout, stdin, stderr
import sys

def S():
	return list(map(str, input().strip()))

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter, deque
import math
import heapq
from heapq import heappop, heappush
import bisect
from math import factorial, inf
from itertools import groupby
from itertools import permutations as comb
mod = 998244353

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

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

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a, b, c):
	print(c, a, b, flush=True)
	n = I()
	return n

def linear_sieve(n):
	is_composite = [False] * n
	prime = []
	for i in range(2, n):
		if not is_composite[i]:
			prime.append(i)
		for j in prime:
			is_composite[i * j] = True
			if i % prime == 0:
				break
	return prime

def dfs(i, p, d):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

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(n)
	return l

def binpow(a, b, c):
	res = 1
	a = a % c
	while b > 0:
		if b & 1:
			res = res * a % c
		b = b >> 1
		a = a * a % c
	return res - 1
d = []
primes = []
prim = [0] * (10 ** 6 + 1)

def sieve(n):
	for i in range(n):
		d.append(i)
	for i in range(2, n):
		if d[i] == i:
			prim[i] = 1
			primes.append(i)
		j = 0
		while j < len(primes) and primes[j] <= d[i] and (primes[j] * i < n):
			d[i * primes[j]] = primes[j]
			j += 1

def primeFactors(n):
	factors = []
	while n != 1:
		factors.append(d[n])
		n //= d[n]
	return factors
t = 1
t = I()
for _ in range(t):
	n = I()
	s = lint()
	curr = s[n - 1]
	res = max(s)
	a = 0
	for i in range(n - 1, -1, -1):
		if curr == res:
			break
		if s[i] > curr:
			curr = s[i]
			a += 1
	print(a)


import array
import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
import itertools
import functools
from types import GeneratorType
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

def bootstrap(f, stack=[]):

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

class Graphs:

	def __init__(self):
		self.graph = graphDict(set)

	def add_edge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)

	def dfs_utility(self, nodes, visited_nodes, colors, parity, level):
		global count
		if nodes == 1:
			colors[nodes] = -1
		elif len(self.graph[nodes]) == 1 and parity % 2 == 0:
			if q == 1:
				colors[nodes] = 1
			else:
				colors[nodes] = -1
				count += 1
		elif parity % 2 == 0:
			colors[nodes] = -1
		else:
			colors[nodes] = 1
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			new_level = level + 1
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes, colors, level - 1, new_level)

	def dfs(self, node):
		Visited = set()
		color = collections.defaultdict()
		self.dfs_utility(node, Visited, color, 0, 0)
		return color

	def bfs(self, node, f_node):
		count = float('inf')
		visited = set()
		level = 0
		if node not in visited:
			queue.append([node, level])
			visited.add(node)
		flag = 0
		while queue:
			parent = queue.popleft()
			if parent[0] == f_node:
				flag = 1
				count = min(count, parent[1])
			level = parent[1] + 1
			for item in self.graph[parent[0]]:
				if item not in visited:
					queue.append([item, level])
					visited.add(item)
		return count if flag else -1
		return False

class Tree:

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

def inorder(node, lis):
	if node:
		inorder(node.left, lis)
		lis.append(node.data)
		inorder(node.right, lis)
	return lis

def leaf_node_sum(root):
	if root is None:
		return 0
	if root.left is None and root.right is None:
		return root.data
	return leaf_node_sum(root.left) + leaf_node_sum(root.right)

def hight(root):
	if root is None:
		return -1
	if root.left is None and root.right is None:
		return 0
	return max(hight(root.left), hight(root.right)) + 1

class UnionFind:
	parents = []
	sizes = []
	count = 0

	def __init__(self, n):
		self.count = n
		self.parents = [i for i in range(n)]
		self.sizes = [1 for i in range(n)]

	def find(self, i):
		if self.parents[i] == i:
			return i
		else:
			self.parents[i] = self.find(self.parents[i])
			return self.parents[i]

	def unite(self, i, j):
		root_i = self.find(i)
		root_j = self.find(j)
		if root_i == root_j:
			return
		elif root_i < root_j:
			self.parents[root_j] = root_i
			self.sizes[root_i] += self.sizes[root_j]
		else:
			self.parents[root_i] = root_j
			self.sizes[root_j] += self.sizes[root_i]

	def same(self, i, j):
		return self.find(i) == self.find(j)

	def size(self, i):
		return self.sizes[self.find(i)]

	def group_count(self):
		return len(set((self.find(i) for i in range(self.count))))

	def answer(self, extra, p, q):
		dic = collections.Counter()
		for q in range(n):
			dic[self.find(q)] = self.size(q)
		hq = list(dic.values())
		heapq._heapify_max(hq)
		ans = -1
		for z in range(extra + 1):
			if hq:
				ans += heapq._heappop_max(hq)
			else:
				break
		return ans

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

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 p_sum(array):
	return list(itertools.accumulate(array))

def base_change(nn, bb):
	if nn == 0:
		return [0]
	digits = []
	while nn:
		digits.append(int(nn % bb))
		nn //= bb
	return digits[::-1]

def diophantine(a: int, b: int, c: int):
	(d, x, y) = extended_gcd(a, b)
	r = c // d
	return (r * x, r * y)

@bootstrap
def extended_gcd(a: int, b: int):
	if b == 0:
		(d, x, y) = (a, 1, 0)
	else:
		(d, p, q) = (yield extended_gcd(b, a % b))
		x = q
		y = p - q * (a // b)
	yield (d, x, y)
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, **kwargs):
		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 inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	n = int(inp())
	arr = list_inp(int)
	x = list(sorted(arr))
	if n == 1 or arr == x:
		print(0)
	else:
		prev = 0
		target = x[-1]
		ans = 0
		for item in arr[::-1]:
			if item > prev:
				prev = item
				if prev == target:
					break
				ans += 1
		print(ans)


test = int(input())
while test:
	n = int(input())
	a = list(map(int, input().split()))
	an = a[n - 1]
	max = 0
	count = 0
	i = n - 1
	while i >= 0:
		if a[i] > max:
			max = a[i]
			count += 1
		i = i - 1
	print(count - 1)
	test = test - 1


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


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	maks = max(x)
	i = n - 1
	res = 0
	while x[i] != maks:
		j = i - 1
		while x[j] <= x[i]:
			j -= 1
		i = j
		res += 1
	print(res)


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


import os
import sys
from io import BytesIO, IOBase
import math as mt
import itertools as it
import operator as op
import bisect as bs
import heapq as hp
from functools import reduce
from io import BytesIO, IOBase
from collections import deque, defaultdict, OrderedDict, Counter, ChainMap, _chain

def nCr(n, r):
	return reduce(op.mul, range(n - r + 1, n + 1), 1) // mt.factorial(r)

def ceil(a, b):
	return (a + b - 1) // b

def lcm(a, b):
	return a * b // mt.gcd(a, b)
gcdm = lambda *args: reduce(mt.gcd, args, 0)

def lcm(a, b):
	return a * b // mt.gcd(a, b)
lcmm = lambda *args: reduce(lcm, args, 1)
_str = str
str = lambda x=b'': x if type(x) is bytes else _str(x).encode()
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
inf = float('inf')

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

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	mx = 0
	idx = -1
	mi = float('inf')
	for i in range(n):
		if mx < a[i]:
			mx = a[i]
			idx = i
		if mx == a[i]:
			idx = max(idx, i)
		mi = min(mi, a[i])
	if idx == n - 1:
		print(0)
		return

	def op(val):
		for i in range(n - 1, -1, -1):
			if a[i] > val:
				return i
	idx = n - 1
	ans = 0
	while a[idx] != mx:
		i = idx - 1
		while a[i] <= a[idx]:
			i -= 1
		idx = i
		ans += 1
	print(ans)
for _ in range(int(input())):
	solve()


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


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
sys.setrecursionlimit(3 * 10 ** 5)
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
x = 0
pref = []
lvl = []
gp = []
ans = []
f = 0
w = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot

def dfs(i, prod, rem, n):
	if rem == 0:
		while i < len(n):
			prod *= int(n[i])
			i += 1
		return prod
	if i == len(n):
		return prod
	mx = 0
	for j in range(9 - int(n[i])):
		mx = max(dfs(i + 1, (int(n[i]) + min(j, rem)) * prod, rem - min(j, rem), n), mx)
	return mx

def hnbhai(tc):
	n = sb()
	a = sd()
	mx = max(a)
	tot = 0
	i = n - 1
	while i >= 0 and a[i] != mx:
		tot += 1
		j = i
		i -= 1
		while i >= 0:
			if a[i] > a[j]:
				break
			i -= 1
	print(tot)
for _ in range(sb()):
	hnbhai(_ + 1)


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


import math
import os
import sys
from sys import *
from decimal import *
from io import BytesIO, IOBase
import threading
from itertools import *
from collections import *
from array import *
import random
M = 10 ** 9 + 7
import heapq
import bisect
from functools import lru_cache
from queue import PriorityQueue
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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 inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

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

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

def ternarysearch(arr, n, key):
	(l, r) = (0, n - 1)
	while l <= r:
		mid = (-l + r) // 3 + l
		mid2 = mid + (-l + r) // 3
		if arr[mid] == key:
			return mid
		if arr[mid2] == key:
			return mid2
		if arr[mid] > key:
			r = mid - 1
		elif arr[mid2] < key:
			l = mid2 + 1
		else:
			l = mid + 1
			r = mid2 - 1
	return -1

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def solven(p, l, a, b, n, res):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] <= A[i]:
				l[i] = max(l[i], l[k] + 1)
	return max(l)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def toString(List):
	return ''.join(List)

def permute(a, l, r, p):
	if l == r:
		p.append(toString(a))
	else:
		for i in range(l, r + 1):
			(a[l], a[i]) = (a[i], a[l])
			permute(a, l + 1, r, p)
			(a[l], a[i]) = (a[i], a[l])

def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		if mid * mid == number:
			ans = mid
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans

def countRectangles(l, w):
	squareSide = math.gcd(l, w)
	return int(l * w / (squareSide * squareSide))

def count_same_digit(L, R):
	tmp = 0
	ans = 0
	n = int(math.log10(R) + 1)
	for i in range(0, n):
		tmp = tmp * 10 + 1
		for j in range(1, 10):
			if L <= tmp * j and tmp * j <= R:
				ans += 1
	return ans

def findCrossOver(arr, low, high, x):
	if arr[high] <= x:
		return high
	if arr[low] > x:
		return low
	mid = (low + high) // 2
	if arr[mid] <= x and arr[mid + 1] > x:
		return mid
	if arr[mid] < x:
		return findCrossOver(arr, mid + 1, high, x)
	return findCrossOver(arr, low, mid - 1, x)

def Kclosest(arr, x, k, n, ans):
	l = findCrossOver(arr, 0, n - 1, x)
	r = l + 1
	count = 0
	if arr[l] == x:
		l -= 1
	while l >= 0 and r < n and (count < k):
		if x - arr[l] < arr[r] - x:
			ans.append(arr[l])
			l -= 1
		else:
			ans.append(arr[r])
			r += 1
		count += 1
	while count < k and l >= 0:
		ans.append(arr[l])
		l -= 1
		count += 1
	while count < k and r < n:
		ans.append(arr[r])
		r += 1
		count += 1
	return ans

def dfs(root, nodeVal, nodeConnection, visited):
	leftVal = nodeVal[root][0]
	rightVal = nodeVal[root][1]
	solution = []
	if nodeConnection[root]:
		visited.add(root)
		for i in nodeConnection[root]:
			if i not in visited:
				solution.append(dfs(i, nodeVal, nodeConnection, visited))
		leftMax = 0
		rightMax = 0
		for i in solution:
			(l, r) = i
			leftMax += max(abs(leftVal - l[0]) + l[1], abs(leftVal - r[0]) + r[1])
			rightMax += max(abs(rightVal - l[0]) + l[1], abs(rightVal - r[0]) + r[1])
		return ((leftVal, leftMax), (rightVal, rightMax))
	else:
		return ((leftVal, 0), (rightVal, 0))

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

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

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def buildPrefix(MAX, prefix):
	prime = [1] * (MAX + 1)
	p = 2
	while p * p <= MAX:
		if prime[p] == 1:
			i = p * 2
			while i <= MAX:
				prime[i] = 0
				i += p
		p += 1
	for p in range(2, MAX + 1):
		prefix[p] = prefix[p - 1]
		if prime[p] == 1:
			prefix[p] += 1

def query(L, R, prefix):
	return prefix[R] - prefix[L - 1]

def maxSubArraySum(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far

def solvepp(n, k):
	if n == 1 and k == 1:
		return 0
	mid = 2 ** (n - 1) // 2
	if k <= mid:
		return solvepp(n - 1, k)
	else:
		return solvepp(n - 1, k - mid) == 0

def solvr(s, p):
	if len(s) == 0:
		print(p, end=' ')
		return
	op1 = p
	op2 = p + s[0]
	s = s[1:]
	solvr(s, op1)
	solvr(s, op2)
	return

def paranthesis(n, m, ans, l):
	if n == 0 and m == 0:
		print(ans)
		return
	if n != 0:
		op1 = ans + '('
		paranthesis(n - 1, m, op1, l)
	if m > n:
		op2 = ans + ')'
		paranthesis(n, m - 1, op2, l)

def rse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(n)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(n)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def lse(arr, n):
	stack = []
	ans = []
	for i in range(n):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	return ans

def mah(arr):
	max1 = 0
	p = rse(arr, len(arr))
	q = lse(arr, len(arr))
	for i in range(len(arr)):
		a = (p[i] - q[i] - 1) * arr[i]
		max1 = max(a, max1)
	return max1

def lcs(s, r):
	rr = len(r)
	ss = len(s)
	l = [[0] * (rr + 1) for i in range(ss + 1)]
	for i in range(1, ss + 1):
		for j in range(1, rr + 1):
			if s[i - 1] == r[j - 1]:
				l[i][j] = l[i - 1][j - 1] + 1
			else:
				l[i][j] = max(l[i - 1][j], l[i][j - 1])
	return l[ss][rr]

def subsetsum(arr, sum, len):
	dp = [[False] * (sum + 1) for i in range(len + 1)]
	for i in range(len + 1):
		dp[i][0] = True
	for i in range(1, len + 1):
		for j in range(1, sum + 1):
			if arr[i - 1] > j:
				dp[i][j] = dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j] or dp[i - 1][j - arr[i - 1]]
	return dp[len][sum]

def matrixmincost(cost, n, m):
	dp = [[0 for x in range(m)] for x in range(n)]
	for i in range(n):
		for j in range(m):
			if i == 0 and j == 0:
				dp[i][j] = cost[i][j]
			elif i == 0 and j != 0:
				dp[i][j] = dp[i][j - 1] + cost[i][j]
			elif j == 0 and i != 0:
				dp[i][j] = dp[i - 1][j] + cost[i][j]
			else:
				dp[i][j] = cost[i][j] + min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1])
	return dp[n - 1][m - 1]

def coinchange(n, arr, len1):
	dp = [0] * (n + 1)
	dp[0] = 1
	for i in range(len1):
		for j in range(arr[i], n + 1):
			dp[j] += dp[j - arr[i]]
	return dp[n]

class Graph(object):

	def __init__(self, vertices):
		self.graph = defaultdict(list)
		self.V = vertices

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def connectedComponents(self):
		unvisited = set(range(self.V))
		queue = deque()
		count = 0
		while len(unvisited) > 0:
			count += 1
			v = next(iter(unvisited))
			unvisited.remove(v)
			queue.append(v)
			while len(queue) > 0:
				v = queue.popleft()
				for w in self.graph[v]:
					if w in unvisited:
						unvisited.remove(w)
						queue.append(w)
		return count

def maxSumIS(arr, n):
	msis = arr.copy()
	for i in range(1, n):
		for j in range(i):
			if arr[i] > arr[j] and msis[i] < msis[j] + arr[i]:
				msis[i] = msis[j] + arr[i]
	c = max(msis)
	p = 5
	return c

def binarysearch2(arr, target):
	lo = 0
	hi = len(arr) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if arr[mid] == target:
			if mid != len(arr) - 1:
				if arr[mid + 1] != target:
					return mid
				else:
					lo += 1
			else:
				return mid
			continue
		if arr[mid] > target:
			hi = mid - 1
		else:
			lo = mid + 1

def nge(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] < arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def nse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] > arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def alperm(nums, path, result):
	if not nums:
		result.add(tuple(path))
		return
	for i in range(0, len(nums)):
		alperm(nums[:i] + nums[i + 1:], path + [nums[i]], result)
	return result

def minsum(arr, n, m, res, l):
	if n == 1 and m == 1:
		res += arr[0][0]
		l.append(res)
	else:
		if n != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n - 1, m, p, l)
		if m != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n, m - 1, p, l)
	return min(l)

def catalan(n):
	if n == 0 or n == 1:
		return 1
	catalan = [0] * (n + 1)
	catalan[0] = 1
	catalan[1] = 1
	for i in range(2, n + 1):
		for j in range(i):
			catalan[i] += catalan[j] * catalan[i - j - 1]
	return catalan[n]

def find_shortest_path(graph, start, end, path):
	path = path + [start]
	if start == end:
		return path
	if start not in graph:
		return None
	shortest = None
	for node in graph[start]:
		if node not in path:
			newpath = find_shortest_path(graph, node, end, path)
			if newpath:
				if not shortest or len(newpath) < len(shortest):
					shortest = newpath
	return shortest

def test(n, d):
	a = random.randint(1, n - 2)
	p = pow(a, d, n)
	if p == 1 or p == n - 1:
		return True
	while d != n - 1:
		d *= 2
		p = pow(p, 2, n)
		if p == n - 1:
			return True
	return False

def isprime(n):
	if n == 1:
		return False
	if n == 2:
		return True
	if n == 3:
		return True
	d = n - 1
	while d % 2 == 0:
		d //= 2
	for i in range(5):
		if test(n, d) == False:
			return False
	return True

def muin(a, m):
	(x, y, mo) = (1, 0, m)
	if m == 1:
		return 0
	while m > 0:
		(x, y) = (y, x - a // m * y)
		(a, m) = (m, a % m)
	if x < 0:
		return mo + x
	else:
		return x

def good(l, c):
	ch = chr(c)
	if len(l) == 1:
		return 1 if ch != l[0] else 0
	k = len(l) // 2
	lm = k - l[:k].count(ch) + good(l[k:], c + 1)
	rm = k - l[k:].count(ch) + good(l[:k], c + 1)
	return min(lm, rm)

def facto(fact):
	(fact[0], fact[1]) = (1, 1)
	for i in range(2, 10 ** 5 + 1):
		fact[i] = fact[i - 1] * i % M

def comb(n, r, fact):
	return fact[n] * pow(fact[n - r] * fact[r], M - 2, M) % M

def numberToBase(n, b):
	if n == 0:
		return 0
	digits = []
	while n:
		digits.append(n % b)
		n //= b
	return sum(digits)

def main():
	tt = 1
	tt = inpu()
	for _ in range(tt):
		n = inpu()
		arr = lis()
		if arr[-1] == max(arr):
			print(0)
			continue
		q = arr[-1]
		p = max(arr)
		ans = 1
		for i in range(n - 1, -1, -1):
			if arr[i] == p:
				break
			if arr[i] > q:
				ans += 1
				q = arr[i]
		print(ans)
main()


def solve():
	N = int(input())
	D = [int(x) for x in input().split()]
	MAX = max(D)
	k = 0
	last = D[N - 1]
	done = D[N - 1] == MAX
	q = N - 1
	while not done:
		p = q - 1
		k = k + 1
		while D[p] <= D[q]:
			p -= 1
		q = p
		done = D[q] == MAX
	return k
T = int(input())
for i in range(T):
	print(solve())


t = int(input())
for case in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	ans = 1
	m = max(l)
	maxi = l[-1]
	if maxi == m:
		print(0)
	else:
		for i in range(n - 1, -1, -1):
			if l[i] == m:
				break
			elif l[i] > maxi:
				maxi = l[i]
				ans += 1
		print(ans)


import sys
input = sys.stdin.readline
case = int(input())
for _ in range(case):
	length = int(input())
	arr = list(map(int, input().split(' ')))
	max_ = arr[-1]
	cnt = 0
	for i in reversed(range(length - 1)):
		if max_ < arr[i]:
			cnt += 1
			max_ = arr[i]
	print(cnt)


import sys, os, getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def readint():
	return int(input())

def readstr():
	return list(map(int, input().split()))
cases = readint()

def solve(num, arr):
	it = 0
	pivot = num - 1
	cur = arr[pivot]
	while pivot >= 0:
		if arr[pivot] > cur:
			cur = arr[pivot]
			it += 1
		pivot -= 1
	return it
output = []
for _ in range(int(cases)):
	num = readint()
	arr = readstr()
	it = solve(num, arr)
	print(it)


import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import *
from collections import defaultdict, deque, Counter
import math, string
from heapq import *
from operator import add
from itertools import accumulate
BUFSIZE = 8192
sys.setrecursionlimit(10 ** 5)

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')
inf = float('inf')
en = lambda x: list(enumerate(x))
ceil_ = lambda a, b: (a + b - 1) // b
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())

def solve():
	n = ii()
	arr = rr()
	m = max(arr)
	brr = arr[::-1]
	c = 1
	d = brr[0]
	for i in brr:
		if i > d:
			c += 1
			d = i
		if d == m:
			break
	print(c - 1)
for _ in ' ' * ii():
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mx = max(arr)
	curr = n - 1
	ans = 0
	while arr[curr] != mx:
		i = curr - 1
		while arr[i] <= arr[curr]:
			i -= 1
		ans += 1
		curr = i
	print(ans)


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)


import sys
input = sys.stdin.readline
c = []
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = max(a)
	if n == 1:
		print(0)
		continue
	i = n
	u = 0
	while True:
		i -= 1
		u += 1
		p = a[i]
		if p == k:
			c.append(u - 1)
			break
		while p >= a[i - 1]:
			i -= 1
print(*c, sep='\n')


import sys

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

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

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

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

def get_list_strings():
	return list(map(str, sys.stdin.readline().strip().split()))

def solve():
	n = get_int()
	arr = get_list()
	if max(arr) == arr[-1]:
		print(0)
		return
	highest = max(arr)
	maxIndex = -1
	for i in range(n - 1, -1, -1):
		if arr[i] == highest:
			maxIndex = i
			break
	ans = 0
	current = float('-inf')
	for i in range(n - 1, maxIndex, -1):
		if arr[i] > current:
			current = arr[i]
			ans += 1
	print(ans)
T = get_int()
while T:
	solve()
	T -= 1


from sys import stdin

def solve():
	results = []
	for _ in range(int(stdin.readline().strip())):
		n = int(stdin.readline().rstrip())
		A = list(map(int, stdin.readline().rstrip().split()))
		if n == 1:
			results.append(0)
			continue
		if n == 2:
			results.append(1 if A[1] < A[0] else 0)
			continue
		B = []
		for (i, x) in enumerate(A):
			B.append((x, i))
		B.sort()
		if B[-1][0] == A[-1]:
			results.append(0)
			continue
		cur = n - 1
		ans = 0
		for i in range(n - 2, -1, -1):
			if A[i] > A[cur]:
				ans += 1
				if A[i] == B[-1][0]:
					break
				cur = i
		results.append(ans)
	print('\n'.join(map(str, results)))
solve()