You have an array $a$ of length $n$. For every positive integer $x$ you are going to perform the following operation during the $x$-th second:

  Select some distinct indices $i_{1}, i_{2}, \ldots, i_{k}$ which are between $1$ and $n$ inclusive, and add $2^{x-1}$ to each corresponding position of $a$. Formally, $a_{i_{j}} := a_{i_{j}} + 2^{x-1}$ for $j = 1, 2, \ldots, k$. Note that you are allowed to not select any indices at all. 

You have to make $a$ nondecreasing as fast as possible. Find the smallest number $T$ such that you can make the array nondecreasing after at most $T$ seconds.

Array $a$ is nondecreasing if and only if $a_{1} \le a_{2} \le \ldots \le a_{n}$.

You have to answer $t$ independent test cases.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^{4}$) — the number of test cases.

The first line of each test case contains single integer $n$ ($1 \le n \le 10^{5}$) — the length of array $a$. It is guaranteed that the sum of values of $n$ over all test cases in the input does not exceed $10^{5}$.

The second line of each test case contains $n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ ($-10^{9} \le a_{i} \le 10^{9}$).


-----Output-----

For each test case, print the minimum number of seconds in which you can make $a$ nondecreasing.


-----Example-----
Input
3
4
1 7 6 5
5
1 2 3 4 5
2
0 -4

Output
2
0
3



-----Note-----

In the first test case, if you select indices $3, 4$ at the $1$-st second and $4$ at the $2$-nd second, then $a$ will become $[1, 7, 7, 8]$. There are some other possible ways to make $a$ nondecreasing in $2$ seconds, but you can't do it faster.

In the second test case, $a$ is already nondecreasing, so answer is $0$.

In the third test case, if you do nothing at first $2$ seconds and select index $2$ at the $3$-rd second, $a$ will become $[0, 0]$.

Source: codeforces | Difficulty: MEDIUM
Tags: Mathematics

Greedy algorithms


Solutions:
import sys
import math

def answer(n, a):
	curr_step = 0
	if n == 1:
		return 0
	mx = a[0]
	mxd = 0
	for i in range(1, n):
		if a[i] > mx:
			mx = a[i]
		d = mx - a[i]
		if d > mxd:
			nsf0 = math.floor(math.log2(d)) + 1
			mxd = 2 ** nsf0 - 1
	return int(math.log2(mxd + 1))

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


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


import math
elem = int(input())
for i in range(elem):
	num = int(input())
	ar = []
	for i in input().split(' '):
		ar.append(int(i))
	curr = 0
	for i in range(len(ar) - 1):
		if ar[i] > ar[i + 1]:
			temp = ar[i] - ar[i + 1]
			ar[i + 1] = ar[i]
			curr = max(curr, temp)
	print(math.ceil(math.log(curr + 1, 2)))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	maxi = a[0]
	fin = 0
	for i in range(1, n):
		if a[i] > maxi:
			maxi = a[i]
		elif maxi - a[i] > fin:
			fin = maxi - a[i]
	if fin <= 2:
		print(fin)
	else:
		print(int(math.log(fin, 2)) + 1)


from math import log2
t = int(input())
for _ in range(0, t):
	n = int(input())
	aa = [int(i) for i in input().split()]
	ans = 0
	for i in range(1, n):
		if aa[i - 1] > aa[i]:
			ans = max(ans, int(log2(aa[i - 1] - aa[i])) + 1)
			aa[i] = aa[i - 1]
	print(ans)


import math

def helper(diff):
	time = math.ceil(math.log2(diff + 1))
	return time
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = 0
	for i in range(1, n):
		if arr[i - 1] > arr[i]:
			x = helper(arr[i - 1] - arr[i])
			res = max(res, x)
			arr[i] = arr[i - 1]
	print(res)


import math

def solve(x):
	return math.floor(math.log2(x))
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	time = -1
	for i in range(1, n):
		if arr[i] < arr[i - 1]:
			x = arr[i - 1] - arr[i]
			arr[i] = arr[i - 1]
			cnt = solve(x)
			if cnt > time:
				time = cnt
	print(time + 1)


from collections import Counter
from math import *
import sys
import bisect as bs
from math import *
mod = 1000000007

def check(n):
	c = 0
	while n > 0:
		n = n - (1 << c)
		c += 1
	return c

def pro(arr):
	n = len(arr)
	maxi = arr[0]
	ans = 0
	for i in range(1, n):
		if maxi <= arr[i]:
			maxi = max(maxi, arr[i])
			continue
		else:
			req = maxi - arr[i]
			ach = check(req)
			ans = max(ans, ach)
	print(ans)
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pro(arr)


def solve(lst):
	if len(lst) == 1:
		return -1
	maximum = lst[0]
	maximum_abs = 0
	flag = True
	for i in range(len(lst) - 1):
		if lst[i] > lst[i + 1]:
			flag = False
		if maximum < lst[i]:
			maximum = lst[i]
		if maximum_abs < abs(maximum - lst[i]):
			maximum_abs = abs(maximum - lst[i])
	i = len(lst) - 1
	if maximum < lst[i]:
		maximum = lst[i]
	if maximum_abs < abs(maximum - lst[i]):
		maximum_abs = abs(maximum - lst[i])
	if flag:
		return -1
	return maximum_abs

def find_answer(num):
	answer = 0
	while num != 0:
		num = num // 2
		answer += 1
	return answer
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if solve(a) == -1:
		print(0)
	else:
		print(find_answer(solve(a)))


def solve(arr):
	diff = 0
	start = arr[0]
	i = 1
	while i < len(arr):
		if arr[i] > start:
			start = arr[i]
		else:
			diff = max(diff, start - arr[i])
		i += 1
	if diff == 0:
		return 0
	return len(format(diff, 'b'))
t = int(input())
ans = []
for s in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans.append(solve(arr))
for it in ans:
	print(it)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	c = a[0]
	g = 0
	for x in a:
		if c < x:
			c = x
		else:
			g = max(g, c - x)
	return g.bit_length()
t = int(input())
for _ in range(t):
	print(solve())


I = input
for _ in range(int(I())):
	I()
	m = -1000000000.0
	l = 0
	for x in map(int, I().split()):
		m = max(m, x)
		l = max(l, m - x)
	print(l and len(f'{l:b}'))


import sys
import math
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = inp()
for c in range(0, t):
	a = inp()
	la = inlt()
	ld = []
	m = -1000000000000
	for d in range(0, a):
		m = max(m, la[d])
		ld.append(la[d] - m)
	if min(ld) == 0:
		print('0')
	else:
		print(str(math.ceil(math.log2(abs(min(ld)) + 1))))


from math import log2, sqrt
R = lambda : map(int, input().split(' '))

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = R()
		max_diff = 0
		prev = next(arr)
		max_num = prev
		for i in arr:
			if max_num < i:
				max_num = i
			else:
				max_diff = max(max_diff, max_num - i)
		if max_diff == 0:
			print(0)
		else:
			print(len(bin(max_diff)) - 2)
main()


import sys
import math as m

def calculateT(argList):
	value = argList[0]
	maxValue = 0
	for i in range(1, len(argList)):
		maxValue = max(maxValue, value - argList[i])
		value = max(value, argList[i])
	if maxValue == 0:
		return 0
	else:
		return int(m.log(maxValue, 2)) + 1

def main():
	counter = 0
	t = 0
	n = 0
	a = []
	for input in sys.stdin:
		counter += 1
		if counter == 1:
			t = int(input)
		elif counter % 2 == 0:
			n = int(input)
		else:
			a = [int(m) for m in input.split()]
			print(calculateT(a))
main()


for i in range(int(input())):
	input()
	max_num = float('-inf')
	max_diff = 0
	for j in map(int, input().split()):
		if j > max_num:
			max_num = j
		else:
			max_diff = max(max_diff, max_num - j)
	if max_diff == 0:
		print(0)
	else:
		print(len(bin(max_diff)) - 2)


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()
		s = 0
		m = a[0]
		for i in range(1, n):
			if a[i] < m:
				sr = m - a[i]
				a[i] = m
				if sr > 2 ** s - 1:
					s = ceil(log(sr + 1, 2))
			else:
				m = a[i]
		print(s)
solve()


import math

def poweredAddition(n, arr):
	used = [-1]
	diffs = []
	ans = 0
	for i in range(1, len(arr)):
		if arr[i] < arr[i - 1]:
			ans = max(ans, int(1 + math.log2(arr[i - 1] - arr[i])))
			arr[i] = arr[i - 1]
	return ans
numCases = int(input())
cases = []
for i in range(numCases):
	n = int(input())
	vals = [int(x) for x in input().split(' ')]
	cases.append([n, vals])
for k in cases:
	answer = poweredAddition(k[0], k[1])
	print(answer)


import math
t = int(input())
while t:
	n = int(input())
	lst = input().split()
	prev = int(lst[0])
	maxdiff = 0
	for i in range(1, n):
		curr = int(lst[i])
		maxdiff = max(maxdiff, prev - curr)
		prev = max(prev, curr)
	if maxdiff == 0:
		print(0)
	else:
		print(int(math.log2(maxdiff)) + 1)
	t = t - 1


import math
import bisect

def printf(str):
	print(str, end=' ')
test_case = int(input())
t = 0
while t < test_case:
	t += 1
	n = int(input())
	ipt = input().split()
	a = list(map(int, ipt))
	mx = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			x = a[i - 1] - a[i]
			x = int(math.floor(math.log2(x))) + 1
			a[i] = a[i - 1]
			mx = max(mx, x)
	print(mx)


def f(L):
	maxm = 0
	n = len(L)
	for i in range(n - 1):
		if L[i + 1] < L[i]:
			maxm = max(maxm, L[i] - L[i + 1])
			L[i + 1] = L[i]
	if maxm == 0:
		return 0
	return len(bin(maxm)) - 2
n = int(input())
for i in range(n):
	m = int(input())
	L = list(map(int, input().split()))
	print(f(L))


import math
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	s = 0
	m = lst[0]
	for i in range(1, n):
		if lst[i] < m:
			s = max(s, abs(m - lst[i]))
		else:
			m = lst[i]
	if s != 0:
		b = math.ceil(math.log(s + 1, 2))
		print(b)
	else:
		print(0)


z = int(input())
while z:
	z -= 1
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	t = 0
	last = a[0]
	for i in range(1, n):
		if a[i] >= last:
			last = a[i]
		else:
			d = last - a[i]
			x = len(bin(d)[2:])
			if x > t:
				t = x
	print(t)


import math
T = int(input())
for t in range(T):
	n = int(input())
	a = [int(e) for e in input().split()]
	m = a[0]
	diff = 0
	for i in range(1, len(a)):
		if m - a[i] > diff:
			diff = m - a[i]
		if a[i] > m:
			m = a[i]
	if diff == 0:
		print(0)
	else:
		print(int(math.log2(diff)) + 1)


tests = int(input())
for t in range(tests):
	ans = 0
	n = int(input())
	num_arr = list(map(int, input().split(' ')))
	for i in range(n - 1):
		diff = num_arr[i + 1] - num_arr[i]
		if diff >= 0:
			continue
		else:
			diff = -diff
			num_arr[i + 1] = num_arr[i]
			ans = max(ans, diff.bit_length())
	print(ans)


n = int(input())
import math
for i in range(n):
	m = int(input())
	l = [int(x) for x in input().split()]
	a = [-10 ** 9]
	for i in range(m):
		a += [max(a[i], l[i])]
	t = 0
	for i in range(m):
		if l[i] < a[i + 1]:
			k = -int(-math.log(a[i + 1] - l[i] + 1, 2) // 1)
			t = max(t, k)
	print(t)


import sys
input = sys.stdin.readline
po = [1]
for i in range(40):
	po += [po[-1] * 2]
for i in range(1, 40):
	po[i] += po[i - 1]
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pre = [arr[0]]
	x = [0]
	for i in arr:
		if pre[-1] > i:
			pre += [pre[-1]]
		else:
			pre += [i]
		x += [pre[-1] - i]
	maxi = max(x)
	for i in range(40):
		if po[i] >= maxi:
			ans = i
			break
	if maxi == 0:
		print(0)
	else:
		print(ans + 1)


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

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

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

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

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

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

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

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

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

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def block(x):
	i = 0
	ans = 0
	while x > 0:
		if x % 2:
			ans = i
		i += 1
		x //= 2
	return ans + 1

def main():
	try:
		for _ in range(inp()):
			n = inp()
			a = inlt()
			ans = 0
			for i in range(1, n):
				if a[i] < a[i - 1]:
					diff = a[i - 1] - a[i]
					ans = max(ans, block(diff))
					a[i] = a[i - 1]
			print(ans)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


import time
import heapq
import sys
from collections import *
from heapq import *
import math
import bisect
from itertools import *
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	temp = [0 for i in range(n)]
	for i in range(1, n):
		if l[i] < l[i - 1]:
			temp.append(l[i - 1] - l[i])
			l[i] = l[i - 1]
	if max(temp) == 0:
		print(0)
	else:
		print(math.floor(math.log2(max(temp))) + 1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a[0]
	d = 0
	for y in a:
		d = max(d, x - y)
		x = max(x, y)
	v = 0
	while d:
		v += 1
		d //= 2
	print(v)


import math
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	maxx = 0
	for j in range(1, n):
		if l[j] >= l[j - 1]:
			continue
		else:
			diff = l[j - 1] - l[j]
			curr = int(math.log(diff, 2)) + 1
			l[j] = l[j - 1]
			if curr > maxx:
				maxx = curr
	print(maxx)


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

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

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

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

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

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		inf = 10 ** 9 + 7
		n = II()
		aa = LI()
		mx = -inf
		mxd = -inf
		for (i, a) in enumerate(aa):
			d = mx - a
			if d > mxd:
				mxd = d
			if a > mx:
				mx = a
		if mxd > 0:
			print(mxd.bit_length())
		else:
			print(0)
main()


for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	m = a[0]
	v = 0
	for i in a:
		v = max(v, m - i)
		m = max(m, i)
	if v == 0:
		print(0)
	else:
		p = 1
		c = 0
		while p <= v:
			p *= 2
			c += 1
		print(c)


from math import log2

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


from math import ceil, log2
for q in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			tmp = bin(a[i - 1] - a[i])[2:]
			res = max(res, len(tmp) - tmp.index('1'))
			a[i] = a[i - 1]
	print(res)


from math import log2
for i in range(int(input())):
	arr_len = int(input())
	nums = [int(g) for g in input().split()]
	x = 0
	for i in range(1, arr_len):
		if nums[i] < nums[i - 1]:
			x = max(x, int(log2(nums[i - 1] - nums[i])) + 1)
			nums[i] = nums[i - 1]
	print(x)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	diff = -1
	var = arr[0]
	i = 1
	while i < n:
		while i < n and arr[i] < var:
			new_d = var - arr[i]
			if diff < new_d:
				diff = new_d
			i += 1
		if i == n:
			break
		var = arr[i]
		i += 1
	if diff == -1:
		print(0)
		continue
	ans = math.floor(math.log2(diff)) + 1
	print(ans)


import math
test = int(input())
for t in range(test):
	n = int(input())
	L = list(map(int, input().split()))
	diff = 0
	for x in range(n - 1):
		if L[x] <= L[x + 1]:
			continue
		else:
			d = L[x] - L[x + 1]
			if d >= diff:
				diff = d
			L[x + 1] = L[x]
	if diff == 0:
		print(0)
		continue
	till = 0
	while diff >= 2 ** till:
		till += 1
	till = int(math.log(diff, 2))
	print(till + 1)


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))

	def p2(x):
		for k in range(1, 100):
			if 2 ** (k - 1) > x:
				return k - 1
	sol = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			x = a[i - 1] - a[i]
			sol = max(sol, p2(x))
			a[i] += x
	print(sol)


import math
for ad in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = 0
	i = 0
	while i < n - 1:
		t = float('inf')
		if l[i + 1] < l[i]:
			for j in range(i + 1, n):
				if l[j] > l[i]:
					break
				t = min(l[j], t)
			m = max(m, l[i] - t)
			i = j - 1
		i += 1
	print(math.ceil(math.log(m + 1, 2)))


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	max_diff = -10 ** 9
	mx = -10 ** 9
	for i in a:
		mx = max(mx, i)
		max_diff = max(max_diff, mx - i)
	print(int(math.log(max_diff + 1, 2) + 0.999999999))


t = int(input())
for _ in range(0, t):
	n = int(input())
	Array = [i for i in map(int, input().split())]
	if len(Array) == 1:
		print(0)
	else:
		MIN = Array[n - 1]
		index = n - 2
		k = Array[index]
		diff = k - MIN
		for j in range(0, n - 2):
			MIN = min(MIN, k)
			index -= 1
			k = Array[index]
			diff = (k - MIN, diff)[diff > k - MIN]
		l = 0
		while 2 ** l - 1 < diff:
			l += 1
		print(l)


from math import *
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	max_diff = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			max_diff = max(max_diff, a[i - 1] - a[i])
			a[i] = a[i - 1]
	if max_diff == 0:
		print(0)
	else:
		print(ceil(log2(max_diff + 1)))


(i, tmp) = (1, 1)
x = [1]
while tmp < 1000000000:
	tmp *= 2
	x.append(x[i - 1] + tmp)
	i += 1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	if n > 1:
		max_diff = 0
		for i in range(1, n):
			if a[i - 1] > a[i]:
				max_diff = max(max_diff, a[i - 1] - a[i])
				a[i] = a[i - 1]
		if max_diff > 0:
			ans = next((idx for (idx, y) in enumerate(x) if y >= max_diff)) + 1
	print(ans)


from math import ceil, log2

def pow2(diff):
	return ceil(log2(diff))
for _ in range(int(input())):
	n = int(input())
	vals = [int(i) for i in input().split(' ')]
	mx = -1
	for i in range(n - 1):
		if vals[i] > vals[i + 1]:
			k = pow2(vals[i] - vals[i + 1])
			if vals[i + 1] + (1 << k) - 1 >= vals[i]:
				k -= 1
			vals[i + 1] = vals[i]
			mx = max(mx, k + 1)
	print(max(mx, 0))


import math
t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = input().split()
	arr = list()
	for i in a:
		arr.append(int(i))
	mx = arr[0]
	mx_diff = 0
	for i in range(1, n, 1):
		if arr[i] > mx:
			mx = arr[i]
		if mx - arr[i] > mx_diff:
			mx_diff = mx - arr[i]
	if mx_diff > 0:
		print(int(math.log(mx_diff, 2)) + 1)
	else:
		print('0')


import math

def run():
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			diff = a[i - 1] - a[i]
			ans = max(ans, math.floor(math.log2(diff)) + 1)
			a[i] = a[i - 1]
	print(ans)
t = int(input())
for i in range(t):
	run()


import sys
import math

def func(d):
	return math.ceil(math.log2(d + 1))

def process(A):
	s = 0
	m = A[0]
	for i in range(1, len(A)):
		if A[i] > m:
			m = A[i]
		elif A[i] < m:
			s1 = func(m - A[i])
			s = max(s, s1)
	print(s)
input = sys.stdin.readline

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

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

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

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

def f(a, n):
	return True

def is_permutation(arr):
	for e in range(1, len(arr) + 1):
		if e not in arr:
			return False
	return True
t = inp()
for i in range(t):
	n = inp()
	A = inlt()
	process(A)


import re

def go():
	n = int(input())
	a = list(map(int, input().split()))
	ma = min(a)
	a = [aa - ma for aa in a]
	cur = 0
	mx = 0
	for aa in a:
		if aa < cur:
			dif = cur - aa
			x = dif.bit_length() - 1
			aa += 1 << x
			mx = max(mx, x + 1)
		cur = max(cur, aa)
	return mx
t = int(input())
ans = []
for _ in range(t):
	ans.append(str(go()))
print('\n'.join(ans))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = 0
	peak = -10 ** 9
	for i in a:
		if i > peak:
			peak = i
		else:
			t = max(t, (peak - i).bit_length())
	print(t)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = a.copy()
	for i in range(n - 1):
		if b[i] > b[i + 1]:
			b[i + 1] = b[i]
	s = max([b[i] - a[i] for i in range(n)])
	print(len(bin(s)) - 2 if s != 0 else 0)


t = int(input())
for e in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(len(a) - 1):
		if a[i] > a[i + 1]:
			s = max(s, a[i] - a[i + 1])
			a[i + 1] = a[i]
	if s == 0:
		print(0)
	else:
		k = 0
		n = 1
		z = 0
		while k != 1:
			z += 2 ** (n - 1)
			if z < s:
				n += 1
			else:
				k = 1
		print(n)


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


from sys import *
t = int(stdin.readline())
import math
for _ in range(t):
	mxd = 0
	mx = 0
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split(' ')))
	for i in range(1, n, 1):
		d = a[i] - a[i - 1]
		if d >= 0:
			continue
		if -d < mxd:
			a[i] = a[i - 1]
			continue
		l = int(math.log(-d, 2)) + 1
		mx = l
		mxd = 2 ** l
		a[i] = a[i - 1]
	print(mx)


import math

def solveAll():
	nbCases = int(input())
	for _ in range(nbCases):
		case = readCase()
		print(solve(case))

def readCase():
	input()
	return [int(x) for x in input().split()]

def solve(nums):
	currentMax = -math.inf
	largestGap = -math.inf
	for num in nums:
		largestGap = max(largestGap, currentMax - num)
		currentMax = max(currentMax, num)
	if largestGap <= 0:
		return 0
	return len(format(largestGap, 'b'))
solveAll()


def powered(n, x):
	cur = x[0]
	dif = 0
	for v in x:
		if v > cur:
			cur = v
		else:
			dif = max(dif, cur - v)
	res = 0
	while dif:
		res += 1
		dif //= 2
	return res
t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	print(powered(n, x))


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

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

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

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

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

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
t = INT()
while t != 0:
	n = INT()
	a = LIST()
	toadd = -INF
	mx = -INF
	for el in a:
		mx = max(mx, el)
		toadd = max(toadd, mx - el)
	print(ceil(math.log(toadd + 1, 2)))
	t -= 1


t = int(input())
for _ in range(t):
	z = 1
	n = int(input())
	arr = list(map(int, input().rstrip().split(' ')))
	curMax = -9999999999
	maxIncrease = 0
	for i in range(n):
		if arr[i] > curMax:
			curMax = arr[i]
		else:
			diff = curMax - arr[i]
			if diff > maxIncrease:
				maxIncrease = diff
	generatedSum = 0
	x = 0
	pow2 = 1
	while generatedSum < maxIncrease:
		x += 1
		generatedSum += pow2
		pow2 = pow2 << 1
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	big = a[0]
	maxi = 0
	for x in a:
		if x > big:
			big = x
		elif big - x > maxi:
			maxi = big - x
	soln = 0
	while maxi > 0:
		maxi //= 2
		soln += 1
	print(soln)


from math import log, ceil
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(lambda x: int(x), input().split()))
	maximum = a[0]
	max_x = 0
	for i in range(0, len(a)):
		if a[i] < maximum:
			temp = int(ceil(log(maximum - a[i] + 1, 2)))
			if temp > max_x:
				max_x = temp
		else:
			maximum = a[i]
	print(max_x)


t = int(input())
import math
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	diff = 0
	maxx = -float('inf')
	sec = 0
	for i in range(n):
		if arr[i] < maxx:
			diff = max(diff, maxx - arr[i])
		maxx = max(maxx, arr[i])
	if diff == 0:
		print(0)
		continue
	if diff != 0:
		sec = int(math.log2(diff))
	if 1 << sec + 1 <= diff:
		sec += 1
	sec += 1
	print(sec)


import math
t = int(input())
ans = 0
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	m = a[0]
	ans = 0
	for i in range(1, n):
		m = max(m, a[i])
		if a[i] < m:
			d = m - a[i]
			ans = max(ans, int(math.log2(d)) + 1)
	print(ans)


import sys
from collections import defaultdict, deque
from math import sqrt

def input():
	return sys.stdin.readline()[:-1]

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	dif = 0
	mx = a[0]
	for i in range(0, n):
		mx = max(mx, a[i])
		dif = max(dif, mx - a[i])
	x = [x for x in bin(dif)[2:]]
	if '1' not in x:
		print(0)
	else:
		print(len(x))
t = int(input())
for _ in range(t):
	solve()


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


def min_2(n):
	if n == 0:
		return 0
	ans = 1
	x = 1
	while n > x:
		n -= x
		ans += 1
		x *= 2
	return ans
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	temp = -10 ** 9
	max_d = 0
	for i in range(len(a)):
		if a[i] == temp:
			pass
		elif temp < a[i]:
			temp = a[i]
		else:
			max_d = max(max_d, temp - a[i])
	print(min_2(max_d))


import math
t = int(input())

def solve(n, a):
	t = 0
	d = -float('inf')
	for i in range(0, len(a)):
		d = max(a[i], d)
		if d - a[i] > 0:
			j = 0
			now = d - a[i]
			while now > 0:
				now >>= 1
				j += 1
			t = max(j, t)
	return t
for _ in range(0, t):
	l = input()
	arr = list(map(int, input().split()))
	seconds = solve(l, arr)
	print(seconds)


import math
import os
import sys
from io import BytesIO, IOBase
from typing import Text
from collections import *
from math import *
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 powered(n, x):
	cur = x[0]
	dif = 0
	for v in x:
		if v > cur:
			cur = v
		else:
			dif = max(dif, cur - v)
	res = 0
	while dif:
		res += 1
		dif //= 2
	return res

def main():
	t = int(input())
	while t > 0:
		t -= 1
		n = int(input())
		arr = list(map(int, input().split()))
		print(powered(n, arr))
	exit(0)
main()


import sys
import math

def solve(A):
	max_so_far = -2 ** 32
	min_diff = 0
	for i in range(len(A)):
		if A[i] < max_so_far:
			min_diff = max(min_diff, max_so_far - A[i])
		else:
			max_so_far = A[i]
	return int(math.log(min_diff, 2)) + 1 if min_diff != 0 else 0
t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(x) for x in sys.stdin.readline().split(' ')]
	print(solve(A))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	T = 0
	prev = a[0]
	for i in range(1, n):
		diff = a[i] - prev
		if diff >= 0:
			prev = a[i]
		else:
			T = max(T, int(1 + math.log2(-diff)))
	print(T)


def susanoo(x):
	ret = 0
	while x:
		ret += 1
		x //= 2
	return ret
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			d = a[i - 1] - a[i]
			ans = max(ans, susanoo(d))
			a[i] = a[i - 1]
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	MAX = -1 << 30
	ANS = 0
	for a in A:
		MAX = max(MAX, a)
		if a < MAX:
			ANS = max(ANS, MAX - a)
	if ANS == 0:
		print(0)
		continue
	for i in range(1, 100):
		if (1 << i) - 1 >= ANS:
			print(i)
			break


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
for qu in range(T):
	N = int(readline())
	A = list(map(int, readline().split()))
	A = [10 ** 9 + a for a in A]
	ctr = A[0]
	ans = 0
	for i in range(1, N):
		a = A[i]
		if a >= ctr:
			ctr = a
			continue
		xx = 0 if ans == 0 else (1 << ans) - 1
		if ctr - a <= xx:
			continue
		a += xx
		while ctr > a:
			a += 1 << ans
			ans += 1
	Ans[qu] = ans
print('\n'.join(map(str, Ans)))


import random, math
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right

def solution(li):
	maxi_till = li[0]
	fin = 0
	for i in range(len(li)):
		if li[i] >= maxi_till:
			maxi_till = li[i] + 1 - 1
		else:
			diff = int(math.log(maxi_till - li[i], 2))
			fin = max(fin, diff + 1)
	return int(fin)

def input_test():
	for _ in range(int(input())):
		n = int(input())
		li = list(map(int, input().strip().split(' ')))
		out = solution(li)
		print(out)

def test():
	pass
input_test()


T = int(input())
for test in range(T):
	N = int(input())
	vec = list(map(int, input().split()))
	diff = []
	mxm = vec[0]
	for i in range(N - 1):
		diff.append(mxm - vec[i + 1])
		mxm = max(mxm, vec[i + 1])
	Tmin = 0
	for d in diff:
		T = 1
		if d <= 0:
			continue
		while 2 ** (T - 1) <= d:
			T += 1
		T -= 1
		Tmin = max(T, Tmin)
	print(Tmin)


def maxi(a):
	ind = 0
	max = -10 ** 9
	for u in range(0, len(a)):
		if a[u] > max:
			max = a[u]
			ind = u
	return ind
t = int(input())
for k in range(0, t):
	n = int(input())
	a = input().split(' ')
	b = []
	for i in range(0, n):
		a[i] = int(a[i])
	for i in range(0, n - 1):
		b.append(a[i] - a[i + 1])
		if i > 0 and b[i - 1] > 0:
			b[i] += b[i - 1]
	p = 0
	ind = maxi(b)
	while len(b) > 0 and b[ind] > 0:
		b[ind] -= 2 ** p
		p += 1
	print(p)


t = int(input())
import math
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	ma = lis[0]
	ans = []
	for j in range(1, len(lis)):
		if lis[j] < ma:
			ans.append(ma - lis[j])
		else:
			ma = lis[j]
	if len(ans) == 0:
		print(0)
	else:
		print(math.ceil(math.log(max(ans) + 1, 2)))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	a = arr[0]
	T = 0
	for j in range(1, n):
		if a < arr[j]:
			a = arr[j]
		else:
			T = max(T, a - arr[j])
	ans = math.log2(T + 1)
	if ans > int(ans):
		ans = int(ans) + 1
	else:
		ans = int(ans)
	print(ans)


import sys

def main():
	res = ''
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		sub_res = 0
		n = int(input())
		a = list(map(int, input().split()))
		for i in range(1, n):
			if a[i] < a[i - 1]:
				k = len(bin(a[i - 1] - a[i])) - 2
				if k > sub_res:
					sub_res = k
				a[i] = a[i - 1]
		res += str(sub_res) + '\n'
	print(res)
main()


import math
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	max1 = 0
	for i in range(1, len(l)):
		if l[i] < l[i - 1]:
			max1 = max(max1, int(math.log(l[i - 1] - l[i], 2) + 1))
			l[i] = l[i - 1]
	print(max1)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	d = 0
	mx = a[0]
	for i in range(1, n):
		if mx - a[i] > d:
			d = mx - a[i]
		if a[i] > mx:
			mx = a[i]
	ans = 0
	c = 0
	p = 1
	while c < d:
		c += p
		p *= 2
		ans += 1
	return ans
t = int(input())
for i in range(t):
	print(solve())


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	for i in range(n - 1):
		dx = a[i + 1] - a[i]
		if dx >= 0:
			continue
		else:
			a[i + 1] = a[i]
			y = 1
			cy = 0
			while y <= -dx:
				y *= 2
				cy += 1
			x = max(x, cy)
	print(x)


import math
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	y = 0
	m = a[0]
	for i in range(1, n):
		m = max(m, a[i])
		y = max(y, m - a[i])
	x = 0
	while 2 ** x <= y:
		x += 1
	print(x)


test_cases = int(input())
second = []
for i in range(int(test_cases)):
	length = input()
	array = [int(idx) for idx in input().split(' ')]
	sec = 0
	idx = 0
	for i in range(int(length) - 1):
		if array[i] > array[i + 1]:
			diff = array[i] - array[i + 1]
			array[i + 1] += diff
			p = 0
			while diff:
				diff = diff // 2
				p += 1
			sec = max(sec, p)
	second.append(sec)
for idx in second:
	print(idx)


def solve(num):
	ans = 0
	binary = bin(num)[2:]
	l = len(binary)
	for i in range(l):
		if binary[i] == '1':
			return l - i
	return 0
t = int(input())
for i in range(t):
	n = int(input())
	data = list(map(int, input().split()))
	m = data[0]
	ans = 0
	for i in range(1, len(data)):
		if data[i] < m:
			diff = m - data[i]
			a = solve(diff)
			if a > ans:
				ans = a
		else:
			m = data[i]
	print(ans)


def next_pow(num):
	b = bin(num)[2:]
	if b.count('1') == 1:
		return len(b) - 1
	else:
		return len(b) - 1

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	score = 0
	m = arr[0]
	for i in range(1, n):
		d = arr[i] - m
		if d < 0:
			k = next_pow(abs(d))
			if k + 1 > score:
				score = k + 1
		if arr[i] > m:
			m = arr[i]
	return score
for _ in range(int(input())):
	print(main())


t = int(input())
for m in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	left = 0
	right = 0
	maxdif = 0
	dif = 0
	while right < n:
		if arr[left] >= arr[right]:
			dif = arr[left] - arr[right]
			if dif > maxdif:
				maxdif = dif
		else:
			left = right
		right += 1
	count = 0
	while maxdif != 0:
		count += 1
		maxdif = maxdif // 2
	print(count)


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

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

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

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
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def solve(c1, c2, maxi1, maxi2):
	for i in range(1, maxi1 + 1):
		if i not in c1:
			return False
	for i in range(1, maxi2 + 1):
		if i not in c2:
			return False
	return True

def main():
	for _ in range(iin()):
		n = iin()
		l = ain()
		x = l[0]
		ans = 0
		for i in range(n):
			ans = max(x - l[i], ans)
			x = max(x, l[i])
		if ans == 0:
			print(0)
		else:
			p = math.log(ans, 2)
			if p % 2 == 0:
				print(int(p + 1))
			else:
				print(int(p + 1))
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')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math as M
for _ in range(int(input())):
	n = int(input())
	A = list((int(i) for i in input().split()))
	ans = 0
	for i in range(1, n):
		if A[i - 1] > A[i]:
			d = A[i - 1] - A[i]
			x = int(M.log2(d) + 1)
			ans = max(ans, x)
			A[i] = A[i - 1]
	print(ans)


from math import log
from math import ceil
T = int(input())
ls = [0] * T
for t in range(T):
	input()
	ls[t] = [int(i) for i in input().split(' ')]

def mins(l):
	l0 = []
	m = l[-1]
	for i in range(len(l) - 1, -1, -1):
		if l[i] < m:
			m = l[i]
		l0.append(m)
	return l0

def ans(l):
	n = mins(l)
	m = 0
	for i in range(len(n)):
		x = l[i] - n[len(n) - 1 - i]
		if x > m:
			m = x
	return ceil(log(1 + m, 2))
for t in range(T):
	print(ans(ls[t]))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def in_int():
	return int(input())

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

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

def in_ints():
	return map(int, input().split())
t = in_int()
import math
from operator import itemgetter
for tt in range(t):
	n = in_int()
	a = in_list()
	pre = a[0]
	mx = 0
	for xx in a[1:]:
		pre = max(pre, xx)
		mx = max(mx, pre - xx)
	if mx == 0:
		print(0)
	else:
		xx = mx
		p = 1
		while xx > 0:
			p = xx & -xx
			xx -= p
		p = math.log2(p)
		print(int(p) + 1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mdiff = 0
	mnum = a[0]
	for i in range(n):
		if mnum < a[i]:
			mnum = a[i]
		else:
			mdiff = max(mdiff, mnum - a[i])
	if mdiff == 0:
		print(0)
	else:
		print(len(bin(mdiff)) - 2)


import math
import sys

def diff_test(set, k):
	for i in range(k):
		increased_one = False
		curmax = set[0]
		for j in range(len(set)):
			if j == 0:
				continue
			if set[j] < curmax:
				increased_one = True
				d = curmax - set[j]
				if d & 1 << i:
					set[j] = set[j] + 2 ** i
			if set[j] > curmax:
				curmax = set[j]
		if increased_one == False:
			print(f'SRINI:did not increase anything in this cycle : i: {i} k: {k} BAD set:')
		print(f'SRINI:diff_test: i{i}: set : {set}')
	for j in range(len(set)):
		if j == 0:
			continue
		if set[j] < set[j - 1]:
			print(f'SRINI: BAD sequence: in set {set} TEST FAILED')
			sys.exit(1)

def find_powered_addition(set):
	diff = []
	maxi = set[0]
	min = maxi
	for i in set:
		if i > maxi:
			diff.append(maxi - min)
			maxi = i
			min = i
		if i < min:
			min = i
	diff.append(maxi - min)
	max_diff = max(diff)
	k = 0
	while max_diff > 0:
		max_diff = max_diff - 2 ** k
		k = k + 1
	print(f'{k}')
total_sets = int(input())
nset = []
set = []
for i in range(total_sets):
	nelements = int(input())
	nset.append(nelements)
	elements = input()
	el_list = []
	for el in elements.split():
		el_list.append(int(el))
	set.append(el_list)
for i in range(len(set)):
	find_powered_addition(set[i])


import math
t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().strip().split()))
	maxi = int(-2000000000.0)
	val = 0
	two_val = 1
	for i in range(len(arr)):
		maxi = max(maxi, arr[i])
		val = max(val, maxi - arr[i])
	step = 0
	while two_val - 1 < val:
		two_val = two_val * 2
		step += 1
	print(step)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	m = a[0]
	p = 0
	for i in range(1, n):
		m = max(m, a[i])
		p = max(p, m - a[i])
	c = 0
	while 2 ** c <= p:
		c += 1
	print(c)


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

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

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

def getStr():
	return input()

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

def solve():
	N = getInt()
	A = getInts()
	if N == 1:
		return 0
	ans = 0
	curr_max = A[0]
	max_move = 0
	for j in range(1, N):
		max_move = max(curr_max - A[j], max_move)
		curr_max = max(A[j], curr_max)
	x = 0
	ans = 0
	two_pow = 0
	while x < max_move:
		x += 2 ** two_pow
		ans += 1
		two_pow += 1
	return ans
two_pows = [2 ** j - 1 for j in range(1, 33)]
T = getInt()
for t in range(T):
	ans = solve()
	print(ans)


import sys
import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, sys.stdin.readline().split()))
	lst = [0] * n
	curr_max = arr[0]
	for i in range(len(arr)):
		if arr[i] < curr_max:
			lst[i] = curr_max - arr[i]
		curr_max = max(curr_max, arr[i])
	s = max(lst)
	print(int(math.log(s, 2)) + 1 if s else 0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(e) for e in input().split()]
	max_a = a[0]
	ans = 0
	for i in range(1, n):
		if a[i] < max_a:
			delta = max_a - a[i]
			c = 0
			while delta > 0:
				delta = delta // 2
				c = c + 1
			if c > ans:
				ans = c
		else:
			max_a = a[i]
	print(ans)


for _ in ' ' * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	maxd = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			maxd = max(maxd, abs(a[i] - a[i - 1]))
			a[i] = a[i - 1]
	c = 0
	while maxd:
		c += 1
		maxd >>= 1
	print(c)


import sys
import math

def num_steps(d):
	ans = 0
	while 2 ** ans - 1 < d:
		ans += 1
	return ans

def solve_test_case(f):
	n = int(f.readline())
	s = f.readline().strip()
	a = [int(x) for x in s.split(' ')]
	ans = 0
	maxs = a[0]
	for x in a:
		maxs = max(x, maxs)
		ans = max(ans, num_steps(maxs - x))
	print(ans)

def solve():
	f = sys.stdin
	tc = int(f.readline())
	for t in range(tc):
		solve_test_case(f)
solve()


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
st = defaultdict(int)
val = 1
for i in range(1, 101):
	st[i] = val
	val *= 2
for _ in range(inn()):
	n = inn()
	a = arr()
	last = -inf
	ans = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			sec = 1
			while a[i] < a[i - 1]:
				a[i] += st[sec]
				sec += 1
			ans = max(ans, sec - 1)
			a[i] = a[i - 1]
	print(ans)


t = int(input())
while t:
	t -= 1
	input()
	a = list(map(int, input().split()))
	(x, m, d) = (0, -1000000000.0, 0)
	for i in a:
		m = max(m, i)
		d = max(d, m - i)
	while d:
		d //= 2
		x += 1
	print(x)


import sys

def get(num):
	count = 0
	while num > 0:
		num //= 2
		count += 1
	return count
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	nax = arr[0]
	ans = 0
	for i in range(1, n):
		nax = max(nax, arr[i])
		if arr[i] == nax:
			pass
		else:
			ans = max(ans, get(nax - arr[i]))
	print(ans)


testCases = int(input())
for i1 in range(testCases):
	x = int(input())
	seq = list(map(int, input().split()))
	req = [0]
	add_req = set([0])
	for i2 in range(1, x, 1):
		temp = seq[i2 - 1] - seq[i2]
		if temp > 0:
			seq[i2] = seq[i2 - 1]
			y = '{0:b}'.format(temp)
			add_req.add(len(y))
	print(max(add_req))


def highest_set_bit(n):
	l = 0
	while n > 0:
		n = n >> 1
		l += 1
	return l
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	time = 0
	for i in range(1, n):
		if a[i - 1] > a[i]:
			dif = a[i - 1] - a[i]
			time = max(time, highest_set_bit(dif))
			a[i] = a[i - 1]
	print(time)
	t -= 1


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	x = arr[0]
	m = 0
	for i in range(1, n):
		y = arr[i]
		if y < x:
			m = max(m, x - y)
		x = max(x, y)
	ans = ceil(log2(m + 1))
	print(ans)


import math

def info(diff):
	nthSec = int(math.ceil(math.log(diff + 1, 2)))
	sum_nth = 2 ** nthSec - 1
	return (nthSec, sum_nth)
t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	(res, nthSec) = (0, 0)
	for i in range(n - 1):
		if lis[i] > lis[i + 1]:
			diff = lis[i] - lis[i + 1]
			if diff > res:
				(nthSec, res) = info(lis[i] - lis[i + 1])
			lis[i + 1] = lis[i]
	print(nthSec)


import math
for i in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	cmax = lis[0]
	maxi = 0
	for i in lis:
		if i > cmax:
			cmax = i
		maxi = max(maxi, cmax - i)
	if maxi == 0:
		print(0)
	else:
		print(int(math.log2(maxi)) + 1)


T = int(input())
for t in range(T):
	N = int(input())
	A = [int(_) for _ in input().split()]
	max_so_far = A[0]
	answer = 0
	for i in range(1, N):
		el = A[i]
		max_so_far = max(max_so_far, el)
		answer = max(answer, (max_so_far - el).bit_length())
	print(answer)


T = int(input())
import math
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	max_diff = 0
	last = a[0]
	for i in range(1, len(a)):
		if a[i] < last:
			diff = last - a[i]
			max_diff = max(diff, max_diff)
		else:
			last = a[i]
	if max_diff == 0:
		print(0)
	else:
		res = int(math.log2(max_diff)) + 1
		print(res)


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	max1 = lst[0]
	max2 = 0
	for i in range(1, n):
		if max1 <= lst[i]:
			max1 = lst[i]
		elif max2 < max1 - lst[i]:
			max2 = max1 - lst[i]
	nd = 0
	while max2 > 0:
		nd += 1
		max2 = max2 - 2 ** (nd - 1)
	print(nd)


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	nl = []
	maxi = l[0]
	for i in range(0, n):
		if maxi < l[i]:
			maxi = l[i]
		nl.append(maxi - l[i])
	k = max(nl)
	if k > 0:
		print(int(math.log2(k)) + 1)
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	answer = 0
	max_so_far = l1[0]
	for i in range(1, n):
		if l1[i] >= max_so_far:
			max_so_far = l1[i]
		else:
			answer = max(answer, (max_so_far - l1[i]).bit_length())
	print(answer)


import heapq
import sys
from math import *
import threading
from heapq import *
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(300000)
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def ncr(n, r):
	return factorial(n) % mod // (factorial(r) % mod * (factorial(n - r) % mod)) if n >= r else 0

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

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

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

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

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

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

def SieveOfEratosthenes(n):
	prime = [{1, i} for i in range(n + 1)]
	p = 2
	while p <= n:
		for i in range(p * 2, n + 1, p):
			prime[i].add(p)
		p += 1
	return prime

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

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def sumk(a, b):
	print('called for', a, b)
	ans = a * (a + 1) // 2
	ans -= b * (b + 1) // 2
	return ans

def sumi(n):
	ans = 0
	if len(n) > 1:
		for x in n:
			ans += int(x)
		return ans
	else:
		return int(n)

def checkwin(x, a):
	if a[0][0] == a[1][1] == a[2][2] == x:
		return 1
	if a[0][2] == a[1][1] == a[2][0] == x:
		return 1
	if len(set(a[0])) == 1 and a[0][0] == x or (len(set(a[1])) == 1 and a[1][0] == x) or (len(set(a[2])) == 1 and a[2][0] == x):
		return 1
	if len(set(a[0][:])) == 1 and a[0][0] == x or (len(set(a[1][:])) == 1 and a[0][1] == x) or (len(set(a[2][:])) == 1 and a[0][0] == x):
		return 1
	return 0
karmanya = int(input())
while karmanya != 0:
	karmanya -= 1
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		diff = a[i - 1] - a[i]
		if diff > 0:
			ans = max(ans, floor(log(diff) / log(2)) + 1)
			a[i] = a[i - 1]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	w = [int(k) for k in input().split()]
	mx = -10 ** 10
	res = 0
	for j in w:
		res = max(res, mx - j)
		mx = max(mx, j)
	print(len(bin(res)[2:]) if res > 0 else 0)


from math import log2
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = 1
	s = 0
	while i < len(l):
		if l[i - 1] > l[i]:
			s = max(s, l[i - 1] - l[i])
			l[i] = l[i - 1]
		i = i + 1
	if s == 0:
		print(0)
		continue
	else:
		j = int(log2(s)) + 1
		print(j)


import sys
import math
inf = int(10000000000.0)
input = sys.stdin.readline
t_ = int(input())
while t_:
	t_ -= 1
	n = int(input())
	lis = list(map(int, input().split()))
	m = lis[0]
	d = 0
	for i in range(n):
		if lis[i] > m:
			m = lis[i]
		d = max(d, m - lis[i])
	m = d
	if m:
		print(int(math.log2(m)) + 1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = a[0]
	b = 0
	for x in a:
		m = max(m, x)
		b = max(b, m - x)
	s = 0
	while b > 0:
		b >>= 1
		s += 1
	print(s)


from sys import stdin
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, stdin.readline().split()))
	prev = l[0]
	diff = []
	for e in l:
		if e < prev:
			diff.append(prev - e)
		else:
			prev = e
	if len(diff) == 0:
		print(0)
	else:
		diff.sort()
		a = diff[-1]
		i = 0
		s = 0
		while a > s:
			s += 2 ** i
			i += 1
		print(i)


import math
inputn = int(input())
ans = []
a = []
for i in range(inputn):
	l = int(input())
	c = input()
	al = c.split()
	m = map(int, al)
	li = list(m)
	tm = 0
	for j in range(1, l):
		t = 0
		if li[j - 1] > li[j]:
			diff = li[j - 1] - li[j]
			n = int(math.log2(diff)) + 1
			if diff <= pow(2, n) - 1:
				t = n
			else:
				t = n
			li[j] = li[j - 1]
		if t > tm:
			tm = t
	ans.append(tm)
for i in ans:
	print(i)


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


def find_T(n):
	a = bin(n)
	m = len(a)
	for i in range(m):
		if a[i] == '1':
			return m - i

def find_ans(n):
	s = list(map(int, input().split()))
	b = s[0]
	ans = 0
	for i in range(1, n):
		if s[i] >= b:
			b = s[i]
		else:
			ans = max(ans, find_T(b - s[i]))
	return ans
for _ in range(int(input())):
	n = int(input())
	print(find_ans(n))


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sol = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			x = a[i - 1] - a[i]
			sol = max(sol, len(bin(x)) - 2)
			a[i] += x
	print(sol)


import math
T = int(input())
for _ in range(T):
	elements = int(input())
	arr = input().split()
	first_element = int(arr[0])
	max_second = 0
	calculations = False
	for el in arr[1:]:
		el = int(el)
		if el < first_element:
			calculations = True
			diff = int(math.log2(first_element - el))
			if diff > max_second:
				max_second = diff
		else:
			first_element = el
	if calculations:
		print(max_second + 1)
	else:
		print(0)


for _ in range(int(input())):
	size = int(input())
	(array, time, check) = (list(map(int, input().split())), -1000000000.0, 0)
	for x in array:
		time = max(time, x)
		check = max(check, time - x)
	print(check and len(f'{check:b}'))


import sys
import math
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	b = a[0]
	c = 0
	for i in range(1, n):
		if a[i] > b:
			b = a[i]
		elif c < b - a[i]:
			c = b - a[i]
	if c == 0:
		print(0)
	else:
		print(math.floor(math.log(c, 2)) + 1)


from math import ceil, log2
for x in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = 0
	cur = 0
	for x in range(1, n):
		if arr[x] < arr[x - 1]:
			res = max(res, int(log2(arr[x - 1] - arr[x])) + 1)
			arr[x] = arr[x - 1]
	print(res)


for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	Ret = 0
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			Bin = bin(a[i] - a[i + 1])[2:]
			Ret = max(Ret, len(Bin) - Bin.index('1'))
			a[i + 1] = a[i]
	print(Ret)


import math
R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
t = R2()
for _ in range(int(t)):
	(n, a) = (R2(), R1())
	l = a[0]
	ans = -10000000000.0
	for i in range(1, n):
		if l > a[i]:
			ans = max(ans, l - a[i])
		else:
			l = a[i]
	if ans <= 0:
		print(0)
	else:
		print(int(math.log2(ans)) + 1)


from sys import stdin, stdout

def f(a, n):
	ans = 0
	m = a[0]
	for i in range(1, n):
		if m > a[i]:
			x = m - a[i]
			bi = len(bin(x)) - 2
			if bi > ans:
				ans = bi
			if m < a[i]:
				m = a[i]
		else:
			m = a[i]
	print(ans)
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	f(a, n)


T = int(input())
for _ in range(T):
	N = int(input())
	a = [int(x) for x in input().split(' ')]
	prv = int(-1000000000.0)
	maxdif = 0
	for x in a:
		if x < prv:
			maxdif = max(maxdif, prv - x)
		else:
			prv = x
	ans = 0
	while maxdif:
		ans += 1
		maxdif //= 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	x = 0
	for i in range(n - 1):
		y = ar[i + 1] - ar[i]
		if y < 0:
			x = max(x, len(bin(-y)) - 2)
			ar[i + 1] = ar[i]
	print(x)


import sys
q = int(input())
ans = []
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	big = a[0]
	need = 0
	for v in a:
		if v < big:
			need = max(need, big - v)
		else:
			big = v
	cur = 0
	p = 0
	while p < need:
		cur += 1
		p *= 2
		p += 1
	ans.append(cur)
print('\n'.join(map(str, ans)))


for w in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a[0]
	l = [0] * 33
	m = -1
	for i in range(33):
		l[i] = pow(2, i)
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			continue
		else:
			diff = a[i - 1] - a[i]
			for j in range(33):
				if l[j] >= diff:
					a[i] = a[i - 1]
					if l[j] == diff:
						m = max(m, j)
					elif j > 0:
						m = max(m, j - 1)
					else:
						m = max(m, j)
					break
	print(m + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	max_val = a[0]
	max_diff = 0
	for i in range(1, n):
		if a[i] > max_val:
			max_val = a[i]
		if max_val - a[i] > max_diff:
			max_diff = max_val - a[i]
	total = 0
	num = 1
	count = 0
	while max_diff > total:
		total += num
		num *= 2
		count += 1
	print(count)


import math
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	for j in range(1, len(l)):
		if l[j] - l[j - 1] < 0:
			c = max(c, int(math.log(l[j - 1] - l[j], 2)) + 1)
			l[j] = l[j - 1]
	print(c)


import math
n = input()
n = int(n)
for i in range(n):
	l = int(input())
	x = input()
	arr = x.split(' ')
	minV = -(1 << 32)
	res = 0
	for j in arr:
		j = int(j)
		if j < minV:
			t = math.ceil(math.log2(minV - j + 1))
			res = max(t, res)
		else:
			minV = j
	print(res)


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	result = 0
	for i in range(1, n):
		diff = lst[i - 1] - lst[i]
		if diff > 0:
			result = max(result, len(bin(diff)) - 2)
			lst[i] = lst[i - 1]
	print(result)


import math
n = int(input())
for _ in range(n):
	m = int(input())
	lis = [int(x) for x in input().split(' ')]
	cur_max = lis[0]
	diff_max = -10000000000.0
	for i in range(1, len(lis)):
		diff = cur_max - lis[i]
		if diff_max < diff:
			diff_max = diff
		if lis[i] > cur_max:
			cur_max = lis[i]
	print(int(math.log2(diff_max) + 1) if diff_max > 0 else 0)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	a = 0
	bits = [0 for i in range(36)]
	ans = 0
	for i in range(1, n):
		if A[i] < A[i - 1]:
			a = A[i - 1] - A[i]
			A[i] = A[i - 1]
			j = 0
			while a:
				a = a // 2
				j += 1
			ans = max(ans, j)
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = []
	for i in range(1, n):
		if A[i] < A[i - 1]:
			B.append(A[i - 1] - A[i])
			A[i] = A[i - 1]
	if len(B):
		ans = math.log(max(B), 2)
		if math.floor(ans) == ans:
			ans += 1
		ans = math.ceil(ans)
		print(ans)
	else:
		print(0)


from math import log2
T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	maxGap = 0
	maxVal = -1000000000
	for i in range(n):
		maxVal = max(maxVal, a[i])
		maxGap = max(maxGap, maxVal - a[i])
	if maxGap == 0:
		print(0)
		continue
	print(int(log2(maxGap)) + 1)


import sys
input = sys.stdin.readline
t = int(input())
out = []
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	big = l[0]
	need = 0
	for v in l:
		if v < big:
			need = max(need, big - v)
		else:
			big = v
	curr = 0
	p = 0
	while p < need:
		curr += 1
		p *= 2
		p += 1
	out.append(curr)
print('\n'.join(map(str, out)))


import sys
from math import sqrt, floor
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().split()))

def a():
	ans = ''
	for _ in range(int(inp())):
		ans += inp()
	print(ans)

def b():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		arr = deque(sorted(read()))
		arr2 = deque()
		for i in range(n // 2):
			arr2.appendleft(arr.pop())
			arr2.appendleft(arr.popleft())
		if arr:
			arr2.appendleft(arr.pop())
		print(*arr2)

def c():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		arr = read()
		mi = 0
		prev = arr[0]
		for i in range(1, n):
			curr = arr[i]
			if curr < prev:
				mi = max(mi, len(bin(prev - curr)[2:]))
			else:
				prev = curr
		ans += str(mi) + '\n'
	print(ans)
c()


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	time = 0
	for i in range(1, n):
		if a[i - 1] > a[i]:
			dif = a[i - 1] - a[i]
			ti = 0
			s = 1
			while a[i - 1] > a[i]:
				a[i] += s
				ti += 1
				s *= 2
			time = max(ti, time)
			a[i] = a[i - 1]
	print(time)
	t -= 1


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def get_x(n, powers):
	k = 0
	power = powers[k]
	while n >= power:
		k += 1
		power = powers[k]
	return k

def solve(a):
	b = []
	b.append(a[0])
	min_x = 0
	powers = [2 ** item for item in range(32)]
	for i in range(1, len(a)):
		if a[i] < b[i - 1]:
			b.append(b[i - 1])
			delta = b[i - 1] - a[i]
			x = get_x(delta, powers)
			if x > min_x:
				min_x = x
		else:
			b.append(a[i])
	return min_x
t = int(input())
for i in range(t):
	n = int(input())
	a = to_list(input())
	print(solve(a))


t = int(input())
for case in range(1, t + 1):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	tick = 0
	prev = -2000000000.0
	for a in arr:
		if a > prev:
			prev = a
		else:
			while a + 2 ** tick - 1 < prev:
				tick += 1
	print(tick)


for _ in ' ' * int(input()):
	a = int(input())
	b = list(map(int, input().split()))
	s = j = 0
	for i in range(1, a):
		if b[i - 1] > b[i]:
			s = max(s, b[i - 1] - b[i])
			b[i] = b[i - 1]
	while s:
		j += 1
		s //= 2
	print(j)


import math

def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	mx = arr[0]
	mdis = 0
	for i in range(1, len(arr)):
		mdis = max(mdis, mx - arr[i])
		mx = max(mx, arr[i])
	if mdis == 0:
		return 0
	for i in range(0, 60):
		mdis -= 1 << i
		if mdis <= 0:
			return i + 1
T = int(input())
while T > 0:
	T -= 1
	print(solve())


t = int(input())
for testcase in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	mx = 0
	for i in range(1, len(a)):
		if a[i] >= a[i - 1]:
			continue
		diff = a[i - 1] - a[i]
		mx = max(mx, len(str(bin(diff))) - 2)
		a[i] = a[i - 1]
	print(mx)


from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(t,) = rl()
for _ in range(t):
	(n,) = rl()
	a = rl()
	m = a[n - 1]
	d = 0
	for i in range(n - 2, -1, -1):
		if a[i] < m:
			m = a[i]
		elif a[i] > m + d:
			d = a[i] - m
	r = 0
	r2 = 1
	while r2 <= d:
		r += 1
		r2 *= 2
	print(r)


t = int(input())
for z in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = l[0]
	s = 0
	for i in range(1, n):
		if l[i] > m:
			m = l[i]
		else:
			s = max(s, -l[i] + m)
	i = 1
	while 2 ** (i - 1) < s:
		i += 1
	if 2 ** (i - 1) > s:
		i -= 1
	l2 = l[:]
	l2.sort()
	if l == l2:
		print(0)
	else:
		print(i)


def msb(num):
	cnt = 0
	while num > 0:
		num >>= 1
		cnt += 1
	return cnt
t = int(input(''))
for i in range(t):
	n = int(input(''))
	a = []
	curr_input = input('')
	for j in curr_input.split(' '):
		a.append(int(j))
	prev = a[0] if len(a) > 0 else 0
	max_diff = 0
	for num in a[1:]:
		curr = 0
		if num < prev:
			curr = prev - num
		prev = curr + num
		max_diff = max(max_diff, curr)
	print(msb(max_diff))


import math

def get_max_Gap(arr):
	mx = arr[0]
	mx_gap = 0
	for i in range(len(arr)):
		mx_gap = max(mx_gap, mx - arr[i])
		mx = max(mx, arr[i])
	return mx_gap

def solution():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		mx = get_max_Gap(arr)
		if mx != 0:
			res = math.ceil(math.log2(mx + 1))
			print(res)
		else:
			print(0)
import sys
import threading
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
thread = threading.Thread(target=solution)
thread.start()
thread.join()


def poweredAddtn(arr):
	m = arr[0]
	add = 0
	x = 0
	for i in arr:
		while m > i + add:
			x += 1
			add += 2 ** (x - 1)
		m = max(m, i)
	print(x)

def main():
	t = int(input())
	for i in range(t):
		input()
		arr = list(map(int, input().split()))
		poweredAddtn(arr)
main()


import math
t = int(input())
for i in range(0, t):
	cantidad = int(input())
	numeros = [int(x) for x in input().split()]
	primero = 0
	contador = 1
	pasos = 0
	lista_menos = []
	lista_mas = []
	anterior = numeros[0]
	diferencia = 0
	while contador < len(numeros):
		primero = contador - 1
		if contador < len(numeros):
			lista = []
			if contador == 1:
				anterior = numeros[0]
			lista.append(numeros[primero])
			while numeros[contador] - numeros[contador - 1] < 0:
				lista.append(numeros[contador])
				contador += 1
				if contador == len(numeros):
					break
			resta = lista[0] - lista[-1]
			if anterior > lista[0]:
				resta += anterior - lista[0]
			anterior = lista[-1] + resta
			if diferencia < resta:
				diferencia = resta
			contador += 1
		else:
			resta = 0
			if numeros[-2] > numeros[-1]:
				resta = numeros[-2] - numeros[-1]
			if diferencia < resta:
				diferencia = resta
			contador += 1
	while 2 ** pasos - 1 < diferencia:
		pasos += 1
	print(pasos)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		diff = a[i] - a[i + 1]
		if diff <= 0:
			continue
		else:
			ans = max(len(bin(diff)) - 2, ans)
			a[i + 1] = a[i]
	print(ans)


from math import log2 as l, floor as f
for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	x = 0
	m = -1e+100
	for i in a:
		m = max(m, i)
		x = max(x, m - i)
	if x == 0:
		print(0)
	else:
		print(f(l(x) + 1))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		mini = 0
		i = 1
		mark = 0
		f = 0
		while i < n:
			if a[i] >= a[i - 1] and f == 0:
				mark = i
				i += 1
				continue
			elif a[i] < a[mark]:
				i += 1
				f = 1
				continue
			else:
				last = i
				d = a[mark] - min(a[mark:last])
				if d > mini:
					mini = d
				f = 0
				i += 1
				mark = last
		if mark != n - 1:
			d = a[mark] - min(a[mark:])
			if d > mini:
				mini = d
		if mini != 0:
			ans = len(bin(mini)[2:])
			print(ans)
		else:
			print(0)


import math
for i in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	b = 0
	for j in range(n - 1):
		if w[j] > w[j + 1]:
			b = max(b, int(math.log2(w[j] - w[j + 1])) + 1)
			w[j + 1] = w[j]
	print(b)


import math
list_ans = []
for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	ans = 0
	a = 0
	b = list1[-1]
	for i in range(n - 2, -1, -1):
		if list1[i] - b > a:
			a = list1[i] - b
		elif list1[i] < b:
			b = list1[i]
	list_ans.append(math.ceil(math.log(a + 1, 2)))
for item in list_ans:
	print(item)


import math

def solve(arr):
	res = 0
	prev_max = arr[0]
	for i in arr[1:]:
		if i < prev_max:
			res = max(res, math.ceil(math.log(prev_max - i + 1) / math.log(2)))
		prev_max = max(i, prev_max)
	print(res)
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	solve(arr)


import math
t = int(input())
ans = []

def solve(a, n):
	b = a[:]
	maxtime = 0
	time = 0
	for x in range(1, n):
		if b[x - 1] > b[x]:
			time = math.ceil(math.log(b[x - 1] - b[x] + 1) / math.log(2))
			maxtime = max(time, maxtime)
			b[x] = b[x - 1]
	return maxtime
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans.append(solve(a, n))
for a in ans:
	print(a)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	max = a[0]
	for i in range(n):
		if max < a[i]:
			max = a[i]
		b.append(max)
	max = 0
	for i in range(n):
		if max < b[i] - a[i]:
			max = b[i] - a[i]
	print(0 if max == 0 else len(bin(max)[2:]))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	c = 0
	for x in range(1, n):
		if a[x] < a[x - 1]:
			c = max(a[x - 1] - a[x], c)
			a[x] = a[x - 1]
	if c == 0:
		print(0)
	else:
		print(int(math.log(c, 2)) + 1)


def f(a):
	max_val = a[0]
	diff = 0
	size = len(a)
	for i in range(size):
		if max_val < a[i]:
			max_val = a[i]
		diff = max(diff, max_val - a[i])
	if diff == 0:
		return 0
	n = 0
	b = 1
	while b - 1 < diff:
		b *= 2
		n += 1
	return n
m = int(input())
res = []
for _ in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	res.append(f(a))
for s in res:
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	maxx = a[0]
	val = []
	for i in a[1:]:
		if maxx > i:
			val.append(maxx - i)
		else:
			maxx = i
	if val:
		x = max(val)
		i = 0
		while x > 0:
			x -= 2 ** i
			i += 1
		print(i)
	else:
		print(0)


import sys
lines = sys.stdin.readlines()
T = int(lines[0].strip())
for t in range(T):
	n = int(lines[2 * t + 1].strip())
	nums = list(map(int, lines[2 * t + 2].strip().split(' ')))
	maxSec = 0
	tmpMax = nums[0]
	for i in range(1, n):
		if nums[i] < tmpMax:
			diff = bin(tmpMax - nums[i])[2:]
			maxSec = max(maxSec, len(diff))
		else:
			tmpMax = nums[i]
	print(maxSec)


t = int(input())
for test_case in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	max_diff = 0
	max_val = array[0]
	for i in range(1, len(array), 1):
		if array[i] < max_val:
			max_diff = max(max_diff, max_val - array[i])
		else:
			max_val = array[i]
	cnt = 0
	if max_diff > 0:
		j = 1
		cnt = 1
		while max_diff > j:
			cnt += 1
			j = j * 2 + 1
	print(cnt)


import sys
import math
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	x = 0
	while i < n:
		curr = i
		minLesser = a[i]
		while i + 1 < n and a[i + 1] < a[curr]:
			minLesser = min(a[i + 1], minLesser)
			i += 1
		x = max(a[curr] - minLesser, x)
		i += 1
	print(int(math.log2(x)) + 1 if x >= 1 else 0)


import math
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	ma = a[0]
	diff = 0
	for i in range(n):
		ma = max(ma, a[i])
		if ma > a[i]:
			temp = ma - a[i]
			diff = max(diff, temp)
	d = math.log(diff + 1) / math.log(2)
	print(math.ceil(d))


import math
from sys import stdin, stdout
t = int(stdin.readline().strip())

def solve():
	n = int(stdin.readline().strip())
	arr = list(map(int, stdin.readline().strip().split()))
	ans = 0
	now = arr[0]
	for i in range(1, len(arr)):
		if arr[i] < now:
			ans = max(ans, len(bin(now - arr[i])[2:]))
		else:
			now = arr[i]
	stdout.writelines(str(ans) + '\n')
while t:
	t -= 1
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	max_till_now = arr[0]
	max_diff = 0
	for i in arr:
		max_till_now = max(max_till_now, i)
		max_diff = max(max_till_now - i, max_diff)
	if max_diff == 0:
		print(0)
	else:
		cnt = 0
		while max_diff:
			max_diff //= 2
			cnt += 1
		print(cnt)


def solve(a):
	maxdiff = 0
	lastmax = a[0]
	for ni in range(1, len(a)):
		if a[ni] > lastmax:
			lastmax = a[ni]
		else:
			maxdiff = max(maxdiff, lastmax - a[ni])
	p = 0
	while maxdiff > 0:
		p += 1
		maxdiff //= 2
	return p
t = int(input())
ans = []
for ti in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans.append(solve(a))
for a in ans:
	print(a)


from cmath import sqrt
import math
from collections import defaultdict, deque, Counter
from functools import reduce
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	mx = 0
	for i in range(1, n):
		if a[i] < a[i - 1]:
			t = math.floor(math.log2(a[i - 1] - a[i])) + 1
			a[i] = a[i - 1]
			mx = max(mx, t)
	print(mx)


def main_function():
	import sys
	input = sys.stdin.readline
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		current_max_num = a[0]
		max_difference = 0
		for el in a:
			if el < current_max_num:
				max_difference = max(max_difference, current_max_num - el)
			else:
				current_max_num = el
		if max_difference == 0:
			print(0)
		else:
			print(len(bin(max_difference)) - 2)
main_function()