Berland State University has received a new update for the operating system. Initially it is installed only on the $1$-st computer.

Update files should be copied to all $n$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.

Your task is to find the minimum number of hours required to copy the update files to all $n$ computers if there are only $k$ patch cables in Berland State University.


-----Input-----

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

Each test case consists of a single line that contains two integers $n$ and $k$ ($1 \le k \le n \le 10^{18}$) — the number of computers and the number of patch cables.


-----Output-----

For each test case print one integer — the minimum number of hours required to copy the update files to all $n$ computers.


-----Examples-----

Input
4
8 3
6 6
7 1
1 1
Output
4
3
6
0


-----Note-----

Let's consider the test cases of the example:

$n=8$, $k=3$:

during the first hour, we copy the update files from the computer $1$ to the computer $2$;

during the second hour, we copy the update files from the computer $1$ to the computer $3$, and from the computer $2$ to the computer $4$;

during the third hour, we copy the update files from the computer $1$ to the computer $5$, from the computer $2$ to the computer $6$, and from the computer $3$ to the computer $7$;

during the fourth hour, we copy the update files from the computer $2$ to the computer $8$.

$n=6$, $k=6$:

during the first hour, we copy the update files from the computer $1$ to the computer $2$;

during the second hour, we copy the update files from the computer $1$ to the computer $3$, and from the computer $2$ to the computer $4$;

during the third hour, we copy the update files from the computer $1$ to the computer $5$, and from the computer $2$ to the computer $6$.

$n=7$, $k=1$:

during the first hour, we copy the update files from the computer $1$ to the computer $2$;

during the second hour, we copy the update files from the computer $1$ to the computer $3$;

during the third hour, we copy the update files from the computer $1$ to the computer $4$;

during the fourth hour, we copy the update files from the computer $4$ to the computer $5$;

during the fifth hour, we copy the update files from the computer $4$ to the computer $6$;

during the sixth hour, we copy the update files from the computer $3$ to the computer $7$.

Difficulty: EASY

Solutions:
l = []
for j in range(61):
	l.append(2 ** j)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	c1 = 0
	c2 = 1
	for j in range(61):
		if l[j] > k:
			c1 = j
			c2 = l[c1]
			break
	c = 0
	if (n - c2) % k != 0:
		c = c + 1
	ans = c + c1 + (n - c2) // k
	print(ans)


for x in range(int(input())):
	(a, b) = list(map(int, input().split()))
	s = 0
	c = 1
	while c < a and c < b:
		c *= 2
		s += 1
	print((a - c + b - 1) // b + s)


t = int(input())
for i in range(t):
	read = input().split()
	n = int(read[0])
	k = int(read[1])
	print(k.bit_length() + (n - 2 ** k.bit_length() - 1) // k + 1)


import math

def solve(n, k):
	k = min(n, k)
	c = 1
	p = 0
	while c <= k:
		c = c * 2
		p = p + 1
	p = p + (n - c) // k
	if (n - c) % k != 0:
		p = p + 1
	return p
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	curr = 1
	while curr < n and curr <= k:
		curr *= 2
		ans += 1
	n -= curr
	if n > 0:
		ans += (n - 1) // k + 1
	print(ans)


testcase = int(input())
for test in range(testcase):
	(n, k) = list(map(int, input().split()))
	hour = 0
	done = 1
	abilitiy = 1
	while done < n:
		done += abilitiy
		hour += 1
		if abilitiy * 2 <= k:
			abilitiy *= 2
		else:
			if (n - done) % k == 0:
				hour += (n - done) // k
			else:
				hour += (n - done) // k + 1
			break
	print(hour)


def solve():
	(n, k) = list(map(int, input().split()))
	(f, ct) = (1, 0)
	while f <= k and f < n:
		f = f * 2
		ct += 1
	if f < n:
		ct += (n - f + k - 1) // k
	print(ct)
t = int(input())
for i in range(t):
	solve()


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 solve():
	(n, k) = getint()
	if k == 1:
		print(n - k)
		return
	a = 1
	res = 0
	while a < k:
		a *= 2
		res += 1
	print(res + (n - a + k - 1) // k)
S()


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	(count, fac) = (0, 1)
	while fac <= k and fac < n:
		fac *= 2
		count += 1
	if fac < n:
		count += (n - fac + k - 1) // k
	print(count)


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	m = len(f'{k:b}') - (k & k - 1 < 1)
	print(m - -(n - 2 ** m) // k)


import sys
for t in range(int(input())):
	(n, k) = map(int, sys.stdin.readline().strip().split())
	ans = 0
	cur = 1
	while cur <= k and cur < n:
		cur *= 2
		ans += 1
	if cur <= n:
		ans += (n - cur + k - 1) // k
	print(ans)


import math

def solve():
	(n, k) = list(map(int, input().split()))
	t = 0
	done = 1
	while done < n:
		if done < k:
			done += done
		else:
			left = n - done
			if left % k == 0:
				t += left // k
			else:
				t += left // k
				t += 1
			return t
		t += 1
	return t
for i in range(int(input())):
	print(solve())


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	curr = 1
	t = 0
	while curr < n and curr < k:
		curr = curr * 2
		t += 1
	if curr < n:
		w = n - curr
		if w % k == 0:
			q = w // k
		else:
			q = w // k + 1
		print(t + q)
	else:
		print(t)


import math

def updateFile(n, k):
	p = 1
	h = 0
	while p < k:
		p *= 2
		h += 1
	if p < n:
		h += (n - p + k - 1) // k
	return h
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	print(updateFile(n, k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	r = 1
	i = 0
	while r < k:
		r += r
		i += 1
	if r < n:
		i += (n - r) // k
		if (n - r) % k != 0:
			i += 1
	print(i)


from sys import stdin

def solve():
	results = []
	for _ in range(int(stdin.readline().strip())):
		(N, K) = map(int, stdin.readline().strip().split())
		if K == 1 or N == 1:
			results.append(N - 1)
			continue
		if K == 2:
			results.append(N // 2 + (1 if N % 2 else 0))
			continue
		if N == 2:
			results.append(1)
			continue
		if N < 5:
			results.append(2)
			continue
		tmp = 4
		cnt = 2
		while tmp < N:
			if K <= tmp:
				cnt += (N - tmp) // K
				if tmp + K * ((N - tmp) // K) < N:
					cnt += 1
				break
			tmp *= 2
			cnt += 1
		results.append(cnt)
	print('\n'.join(map(str, results)))
solve()


import os
import sys
import time

def timer(f):

	def wrapper(*args, **kwargs):
		start_time = time.time()
		result = f(*args, **kwargs)
		end_time = time.time()
		if os.environ.get('LOCAL_RUN'):
			print(f'Procesing time: {end_time - start_time} seconds')
		return result
	return wrapper

def main(fin):
	n = int(input())
	for i in range(n):
		solve(fin)

def solve(fin):
	(a, k) = [int(i) for i in input().split()]
	result = 0
	curr = 1
	while curr <= k and curr < a:
		curr *= 2
		result += 1
	if curr < a:
		result += (a - curr + k - 1) // k
	print(result)
if os.environ.get('LOCAL_RUN'):
	fin = open('input.txt')
else:
	fin = sys.stdin
main(fin)


def solve(inp):
	(n_computer, n_cable) = inp.split()
	n_cable = int(n_cable)
	n_computer = int(n_computer)
	files = 1
	hours = 0
	while files < n_cable:
		files *= 2
		hours += 1
	need = n_computer - files
	if need % n_cable == 0:
		hours += need // n_cable
	else:
		hours += need // n_cable + 1
	print(hours)
n = int(input())
inp = []
for i in range(n):
	inp.append(input())
for i in inp:
	solve(i)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = 1
	hours = 0
	x = bin(k)[2:]
	if x.count('1') == 1:
		a = 2 ** (len(x) - 1)
		hours += len(x) - 1
	else:
		a = 2 ** len(x)
		hours += len(x)
	diff = n - a
	if diff > 0:
		hours += (diff + (k - 1)) // k
	print(hours)


import math
t = int(input())
for i in range(0, t):
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	time = len(bin(k)[2:])
	if n == 1:
		print(0)
	elif k == 1:
		print(n - 1)
	elif n == 2 ** (time - 1):
		print(time - 1)
	elif n <= 2 ** time:
		print(time)
	else:
		if (n - 2 ** time) % k != 0:
			print(time + -1 * (n - 2 ** time) // k * -1)
		else:
			print(time + -1 * (n - 2 ** time) // k * -1)
		2


tc = int(input())

def log(k):
	(count, i) = (0, 0)
	while 1 << i < k:
		count += 1
		i += 1
	return count
for i in range(tc):
	(a, b) = map(int, input().split())
	x = log(b)
	ans = x
	x = 1 << x
	a -= x
	ans += (a + b - 1) // b
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	temp = 1
	count = 0
	while temp <= k and temp < n:
		temp *= 2
		count += 1
	if temp < n:
		count += (n - temp + k - 1) // k
	print(count)


import sys
input = sys.stdin.readline
from math import log2, ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n -= 1
	if n == 0:
		print(0)
	elif k > (n + 1) // 2:
		print(len(bin(n)[2:]))
	else:
		x = ceil(log2(k))
		n -= 2 ** x - 1
		print(x + (n + k - 1) // k)


import math
t = int(input())
for i in range(0, t):
	(n, k) = [int(x) for x in input().split()]
	count = 1
	time = 0
	no_of_data_comp = 1
	if n >= k:
		time = len(bin(k)[2:])
		no_of_data_comp = 2 ** time
		left = n - no_of_data_comp
		if left % k == 0:
			time += left // k
		else:
			time += left // k + 1
		print(time)
	else:
		time = len(bin(n)[2:])
		print(time)


import sys
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 solve(n, k):
	(curr, hours) = (1, 0)
	n -= 1
	while n > 0 and curr < k:
		n -= curr
		curr *= 2
		hours += 1
	return hours + (n + k - 1) // k
for _ in range(rn()):
	(n, k) = rnt()
	print(solve(n, k))


from collections import Counter, defaultdict, OrderedDict, deque
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from typing import List
import itertools
import math
import heapq
import string
import random
(MIN, MAX, MOD) = (-1061109567, 1061109567, 1000000007)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

def N():
	return int(input())
for _ in range(N()):
	(n, k) = RL()
	ans = 0
	cur = 1
	while cur < k:
		cur += cur
		ans += 1
	if cur >= n:
		print(ans)
	else:
		print(ans + (n - cur + k - 1) // k)


def log(x):
	c = 0
	while x != 1:
		x //= 2
		c += 1
	return c
t = int(input())
while t:
	(n, k) = [int(i) for i in input().split()]
	if n == 1:
		print(0)
	elif k == 1:
		print(n - 1)
	else:
		ans = log(k)
		active = pow(2, ans)
		if active == n:
			print(ans)
		else:
			if active == k:
				if (n - k) % k != 0:
					ans += (n - k) // k + 1
				else:
					ans += (n - k) // k
			else:
				ans += 1
				active *= 2
				if (n - active) % k != 0:
					ans += (n - active) // k + 1
				else:
					ans += (n - active) // k
			print(ans)
	t -= 1


import sys
from collections import deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
fast = lambda : sys.stdin.readline()
test_case = 1
test_case = int(input())
sys.setrecursionlimit(10 ** 6)

def ans():
	(n, k) = ari()
	ans = 0
	start = 1
	while start < k:
		start *= 2
		ans += 1
	n = n - start
	ans += n // k
	if n % k != 0:
		ans += 1
	print(ans)
for _ in range(test_case):
	ans()


import sys
readline = sys.stdin.readline
n = int(readline())
for i in range(n):
	(n, k) = map(int, readline().split())
	c = 1
	ans = 0
	while c <= k and c < n:
		ans += 1
		c *= 2
	if c <= n:
		ans += (n - c + k - 1) // k
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	cnt = 1
	ans = 0
	while cnt <= k and cnt < n:
		cnt *= 2
		ans += 1
	if cnt >= n:
		return ans
	else:
		ans += (n - cnt) // k
		ans += 1 if (n - cnt) % k else 0
		return ans
for _ in range(int(input())):
	print(solve())


for s in range(int(input())):
	(n, k) = map(int, input().split())
	m = (k - 1).bit_length()
	print(m - (2 ** m - n) // k)


from math import ceil

def solve():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		ans = 0
		cur = 1
		while cur < k:
			cur *= 2
			ans += 1
		ans += int((n - cur + k - 1) // k)
		print(ans)
solve()


import math
import sys

def copy_hours(n, k):
	a = 0
	copy_computers = 1
	n = n - copy_computers
	while copy_computers <= k and n > 0:
		a += 1
		n = n - copy_computers
		copy_computers = copy_computers * 2
	if n > 0:
		a += n // k + (n % k != 0)
	return a
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	print(copy_hours(n, k))


def fun(n, k):
	if n == 1 or n == 2:
		return n - 1
	power = len(bin(k)[2:])
	ans = power
	if n == k and 2 ** (power - 1) == n:
		return ans - 1
	diff = max(0, n - 2 ** power)
	ans += diff // k
	if diff % k > 0:
		ans += 1
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(fun(n, k))


from sys import stdin
lst = list(map(int, stdin.read().split()))
_s = 0

def inp(n=1):
	global _s
	ret = lst[_s:_s + n]
	_s += n
	return ret

def inp1():
	return inp()[0]
t = inp1()
for _ in range(t):
	n = inp1()
	k = inp1()
	done = 1
	time = 0
	while done <= k and done < n:
		done += done
		time += 1
	if done < n:
		time += (n - done + k - 1) // k
	print(time)


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, k) = rns()
	n -= 1
	ans = 0
	add = 1
	while n > 0 and add < k:
		n -= add
		add *= 2
		ans += 1
	if n > 0:
		ans += ceil_div(n, k)
	print(ans)


n = int(input())
ret = []
for i in range(n):
	(cp, code) = map(int, input().split())
	ans = 0
	updated = 1
	while updated < cp:
		if updated > code:
			break
		updated *= 2
		ans += 1
	ans += max(0, (cp - updated) // code)
	if max(0, cp - updated) % code != 0:
		ans += 1
	ret.append(ans)
print(*ret, sep='\n')


def solve(n, k):
	cnt = 1
	ans = 0
	while cnt < k and cnt < n:
		ans += 1
		cnt *= 2
	if cnt >= n:
		print(ans)
	else:
		print(ans + (n - cnt + k - 1) // k)

def read():
	(n, k) = map(int, input().split())
	solve(n, k)
for tcase in range(int(input())):
	read()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	start = 1
	hours = 0
	while start < k:
		start += min(start, k)
		hours += 1
	if start == n:
		print(hours)
	else:
		hours += (n - start + k - 1) // k
		print(hours)


from math import log2, floor, ceil

def findLg(n):
	tot = 0
	while n > 0:
		n = n >> 1
		tot += 1
	return tot - 1
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k <= 2 ** 32:
		lg = floor(log2(k)) + 1
	else:
		lg = findLg(k) + 1
	if n <= 2 ** 32:
		if 2 ** lg >= n:
			print(ceil(log2(n)))
		else:
			n -= 2 ** lg
			print(int(lg + ceil(n / k)))
	elif 2 ** lg >= n:
		llg = findLg(n)
		print(llg + 1 * (n != 2 ** llg))
	else:
		n = n - 2 ** lg
		print(int(lg + n // k + 1 * (n % k > 0)))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	i = 0
	comps = 1
	for i in range(10 ** 7):
		if comps >= n:
			break
		if comps <= k:
			comps *= 2
			i += 1
		else:
			c = (n - comps - 1) // k + 1
			i += c
			break
	print(i)


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	z = (k - 1).bit_length()
	print(z - (2 ** z - n) // k)


import math

def ob(n, k):
	z = math.ceil(math.log2(k))
	return int(z + (n - math.pow(2, z) + k - 1) // k)

def med(nn, kk):
	t = 0
	nnn = 1
	while nnn < kk:
		nnn += nnn
		t += 1
	t += (nn - nnn + k - 1) // k
	return t
z = int(input())
for i in range(z):
	(n, k) = map(int, input().split())
	print(med(n, k))


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	times = 0
	while 1 << times < n and 1 << times <= k:
		times += 1
	if 1 << times >= n:
		print(times)
	else:
		print((n - (1 << times) + k - 1) // k + times)


test_cases = input()
for i in range(int(test_cases)):
	count = list(map(int, input().split(' ')))
	bits = count[1].bit_length()
	hours = bits
	if pow(2, bits - 1) == count[1]:
		bits = bits - 1
		hours = bits
	if count[0] > pow(2, bits):
		hours = hours + -1 * (count[0] - pow(2, bits)) // count[1] * -1
	print(hours)


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	avail = 1
	hours = 0
	while avail < k and avail < n:
		avail <<= 1
		hours += 1
	if avail >= n:
		print(hours)
	else:
		hours += (n - avail) // k
		if (n - avail) % k:
			hours += 1
		print(hours)


import sys
readline = sys.stdin.readline
t = int(readline())
while t:
	(n, k) = map(int, readline().split())
	i = 1
	ans = 0
	while i <= k and i < n:
		i *= 2
		ans += 1
	if i <= n:
		ans += (n - i - 1) // k + 1
	print(ans)
	t -= 1


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	ans = len(bin(k)) - 2
	temp = n - 2 ** ans
	if n == k and bin(n).count('1') == 1:
		ans = ans - 1
	elif temp > 0:
		ans = ans + temp // k
		if temp % k != 0:
			ans = ans + 1
	print(ans)


def f():
	(n, k) = map(int, input().split())
	cnt = 1
	t = 0
	while cnt < k:
		if cnt >= n:
			print(t)
			return
		cnt <<= 1
		t += 1
	if cnt >= n:
		print(t)
		return
	n -= cnt
	print(n // k + (n % k != 0) + t)
t = int(input())
for i in range(t):
	f()


from math import log
for u in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n - 1)
	else:
		b = int(log(k + 1, 2))
		ans = 2 ** b
		if ans < k:
			b += 1
			ans *= 2
		if n - ans > 0:
			b += (n - ans + k - 1) // k
		print(b)


from sys import stdin

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

def lcm(a, b):
	return a * b // gcd(a, b)
t = int(stdin.readline().rstrip())
while t > 0:
	(n, k) = map(int, stdin.readline().split())
	ans = 1
	hours = 0
	p = 1
	ax = 0
	while p < k:
		hours += 1
		ax = p
		p = p + p
	n -= p
	if n % k == 0:
		print(hours + n // k)
	else:
		print(hours + n // k + 1)
	t -= 1


from collections import deque
import heapq
from math import sqrt
import operator
from operator import itemgetter
import sys
import time
import copy
inf_var = 0
if inf_var == 1:
	inf = open('input.txt', 'r')
else:
	inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_one_float():
	return float(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split()]
	return res

def read_list_of_ints_zero():
	return [int(val) - 1 for val in input().rstrip('\n').split()]

def read_str():
	return input().rstrip()

def main():
	tests = read_one_int()
	for _ in range(tests):
		(n, k) = read_list_of_ints()
		res = 1
		used = 1
		left = False
		if n == 1:
			print(0)
			continue
		if n == 2:
			print(1)
			continue
		while True:
			used <<= 1
			res += 1
			if k >= used:
				if used << 1 >= n:
					break
			else:
				left = True
				break
		if left and used < n:
			res += (n - (used + k)) // k
			if (n - (used + k)) % k:
				res += 1
		print(res)
main()


import math
t = int(input())

def solve():
	(n, k) = map(int, input().split())
	x = 1
	ans = 0
	while x < n and x <= k:
		x <<= 1
		ans += 1
	if n > x:
		add = (n - x + k - 1) // k
		print(ans + add)
	else:
		print(ans)
for _ in range(t):
	solve()


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(nmbr()):
	(n, k) = lst()
	wire = 1
	ans = 2
	if n == 1:
		print(0)
		continue
	cnt = 1
	while wire * 2 <= k and wire * 2 <= n:
		wire *= 2
		ans = wire * 2
		cnt += 1
	left = n - ans
	times = left // k
	rem = int(left % k != 0)
	print(cnt + times + rem)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	hours = 0
	new = 1
	done = 1
	while new < k and done < n:
		hours += 1
		done += new
		new *= 2
	left = n - done
	if left > 0:
		if left % k == 0:
			hours += left // k
		else:
			hours += left // k + 1
	print(hours)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	f = 0
	while pow(2, f) < k:
		f += 1
	t = f
	n -= pow(2, f)
	t += (n + k - 1) // k
	print(t)


import sys
import collections
import heapq
r = lambda : sys.stdin.readline().rstrip()
MIS = lambda : map(int, r().split())
for _ in range(int(r())):
	(N, K) = MIS()
	cnt = 0
	a = 1
	while 1:
		if a >= K:
			break
		cnt += 1
		a *= 2
	print(cnt + (N - a - 1) // K + 1)


t = int(input())

def solve(n, k):
	if k == 1:
		return n - 1
	h = (k - 1).bit_length()
	ans = h + (n - (1 << h) + k - 1) // k
	return ans
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


T = int(input())
import math
for _ in range(T):
	(a, b) = map(int, input().split())
	tmp_t = 0
	tmp_s = 1
	while tmp_s <= b:
		if tmp_s >= a:
			break
		tmp_s *= 2
		tmp_t += 1
	if tmp_s >= a:
		print(tmp_t)
		continue
	print(tmp_t + -(-(a - tmp_s) // b))


import math
t = int(input())
while t > 0:
	(m, k) = map(int, input().split())
	if m == 1:
		print(0)
		t -= 1
		continue
	power = k.bit_length() - 1
	if 2 ** power == m:
		print(power)
		t -= 1
		continue
	computer = 2 ** (power + 1)
	hours = power + 1
	if m > computer:
		m -= computer
		if m % k == 0:
			hours += m // k
		else:
			hours += m // k + 1
	print(hours)
	t -= 1


from sys import stdin
import math
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1 or n == 1:
		print(n - 1)
		continue
	val1 = int.bit_length(k) - 1
	val1 = val1 + (1 if k - pow(2, val1) > 0 else 0)
	val2 = int.bit_length(n) - 1
	val2 = val2 + (1 if n - pow(2, val2) > 0 else 0)
	if n <= k:
		print(val2)
	else:
		time = val1
		n -= pow(2, time)
		if n > 0:
			print(time + n // k + (1 if n % k > 0 else 0))
		else:
			print(time)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	(a, b) = map(int, sys.stdin.readline().split())
	k = 1
	c = 0
	while k <= b and k < a:
		k *= 2
		c += 1
	if k < a:
		c += (a - k + b - 1) // b
	sys.stdout.write(str(c))
	sys.stdout.write('\n')


import io
import os
FILE_INPUT_MODE = 0
if FILE_INPUT_MODE >= 0:
	if FILE_INPUT_MODE == 1:
		CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
		FD = os.open(f'{CURRENT_DIR}\\input.txt', os.O_RDONLY)
	elif FILE_INPUT_MODE == 0:
		FD = 0
	DATA = io.BytesIO(os.read(FD, os.fstat(FD).st_size))
	if FD != 0:
		os.close(FD)

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

def solve(n, k):
	t = 0
	cur = 1
	cp = 1
	while cur < n:
		t += 1
		cur += cp
		cp = min(cur, k)
		if cp == k:
			break
	if cur >= n:
		return t
	return t + (n - cur - 1) // k + 1

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = [int(word) for word in input().strip().split()]
		print(solve(n, k))
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	x = 1
	ans = 0
	while x < m:
		x *= 2
		ans += 1
	if x < n:
		print(ans + (n - x + m - 1) // m)
	else:
		print(ans)


t = int(input())
while t > 0:
	t = t - 1
	(n, k1) = map(int, input().split())
	itr = 1
	ress = 0
	a = 1
	c = 0
	while itr <= k1 and itr < n:
		if c == 1:
			itr = itr * itr
		else:
			itr = itr * 2
			ress += 1
	if itr >= n:
		a = a + 1
	else:
		ress = ress + (n - itr + k1 - 1) // k1
	print(ress)


import sys
import re
ntests = int(sys.stdin.readline())
for _ in range(ntests):
	inval = sys.stdin.readline().strip()
	(ncomps, ncables) = inval.split()
	ncomps = int(ncomps)
	ncables = int(ncables)
	ans = 0
	txed = 1
	while txed < ncomps:
		if txed < ncables:
			txed += txed
			ans += 1
		elif ncomps <= txed + ncables:
			txed += ncables
			ans += 1
		else:
			steps = (ncomps - txed) // ncables
			txed += ncables * steps
			ans += steps
	print(ans)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	r = 1
	c = 0
	while r <= k and r < n:
		r *= 2
		c += 1
	if n > r:
		c += (n - r + k - 1) // k
	print(c)


from sys import stdin
import math
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	cur = 1
	res = 0
	for i in range(1, k + 1):
		if cur >= n or cur >= k:
			break
		cur *= 2
		res += 1
	if cur < n:
		(a, b) = divmod(n - cur, k)
		res += a + (b > 0)
	print(res)


final = []
cases = int(input())
for _ in range(cases):
	(n, k) = map(int, input().split())
	ans = 0
	rem = n - 1
	avail = 1
	while n > avail:
		if avail <= k:
			avail *= 2
			ans += 1
		else:
			undone = n - avail
			ans += (undone + k - 1) // k
			break
	final.append(ans)
for a in final:
	print(a)


import math

def solve():
	(n, k) = [int(i) for i in input().split(' ')]
	s = 0
	t = 1
	while t < n and t < k:
		t *= 2
		s += 1
	print(s + (n - t + k - 1) // k)
for _ in range(int(input())):
	solve()


t = int(input())
import math

def timnhiphan(key):
	l = 0
	r = 63
	kq = 33
	while l <= r:
		x = (l + r) // 2
		if a[x] <= key:
			kq = x
			l = x + 1
		else:
			r = x - 1
	return kq
a = []
for i in range(64):
	a.append(2 ** i)
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	h = timnhiphan(k)
	if n == 1:
		print(0)
	elif k == 1:
		print(n - 1)
	elif n - 1 >= 2 ** (h + 1) - 1:
		n = n - 2 ** (h + 1)
		time = h + 1
		time = time + n // k
		if n % k != 0:
			time += 1
		print(time)
	else:
		h = timnhiphan(n)
		if n == 2 ** h:
			print(h)
		else:
			print(h + 1)


import sys

def rall():
	return sys.stdin.readlines()

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

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something=''):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array):
	return array
NT = int(rl())
for ti in range(NT):
	(n, k) = map(int, rl().split(' '))
	pow2 = 0
	ktemp = k
	while ktemp > 0:
		ktemp >>= 1
		pow2 += 1
	if 1 << pow2 - 1 == k:
		pow2 -= 1
	nhrs = pow2
	nupd = 1 if pow2 == 0 else 1 << pow2
	nrem = n - nupd
	nturns = nrem // k + (0 if nrem % k == 0 else 1)
	nhrs += nturns
	pr(nhrs)


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	u = 1
	if n == 1:
		print(0)
		continue
	count = 0
	n -= 1
	while u <= m and n > 0:
		n -= u
		u *= 2
		count += 1
	if n <= 0:
		n = 0
	count += n // m
	if n % m:
		count += 1
	print(count)


import sys
import math
for _ in range(int(sys.stdin.readline())):
	(n, k) = map(int, sys.stdin.readline().split())
	updated = 1
	res = 0
	while updated < k:
		res += 1
		updated *= 2
	if updated < n:
		res += (n - updated + k - 1) // k
	print(res)


from __future__ import print_function
from math import *
from collections import deque
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')
mod = 10 ** 9 + 7

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

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

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

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

def ceeil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
for _ in range(inp()):
	(a, b) = invr()
	cur = 1
	t = 0
	while cur <= b and cur < a:
		cur *= 2
		t += 1
	left = a - cur
	if left > 0:
		t += ceeil(left, b)
	print(t)


from sys import stdin
from math import ceil
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')
mod = 10 ** 9 + 7
for _ in range(rn()):
	(n, k) = rns()
	ans = 0
	if n != 1:
		m = 0
		while 2 ** m < k:
			m += 1
		n -= 2 ** m
		ans = m
		ans += n // k + (n % k != 0)
	print(ans)


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, k) = zzz()
	done = 1
	time = 0
	while done <= k and done < n:
		done <<= 1
		time += 1
	print(time + ceil((n - done + (k - 1)) // k) if done <= n else time)


import sys
import math
inpu = sys.stdin.readline
prin = sys.stdout.write
t = int(inpu())
for _ in range(t):
	(n, k) = map(int, inpu().split())
	l = len(bin(k)) - 3
	count = 2 ** (l + 1)
	steps = l + 1
	if n <= count:
		if n == 1:
			print(0)
		else:
			print(len(bin(n - 1)) - 2)
	else:
		mod = (n - count) % k
		needed = (n - count) // k
		if mod > 0:
			needed += 1
		print(steps + needed)


def log2(x):
	i = 1
	k = 0
	while i < x:
		i *= 2
		k += 1
	return k
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	process = 1
	add = log2(k)
	hours = add
	process = pow(2, add)
	hours += (n - process) // k
	if (n - process) % k != 0:
		hours += 1
	print(int(hours))


def solution(n, k):
	cur = 1
	c = 0
	while cur < k:
		c += 1
		cur *= 2
	if cur < n:
		c += (n - cur + k - 1) // k
	return c
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	out = solution(n, k)
	print(out)


for _ in range(int(input())):
	inp = input().split(' ')
	n = int(inp[0])
	k = int(inp[1])
	avail = 1
	h = 0
	while True:
		if avail >= n:
			break
		if avail >= k:
			break
		avail <<= 1
		h += 1
	if avail >= n:
		print(h)
	else:
		print(h + (n - avail + k - 1) // k)


from math import log2
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n -= 1
	(curr, t, s) = (1, 1, 1)
	while curr * 2 < k:
		curr *= 2
		s += curr
		t += 1
	n -= s
	t += n // k + bool(n % k > 0)
	print(t)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	c = 1
	tot = 1
	count = 0
	while tot < n:
		tot += c
		count += 1
		if c * 2 < k:
			c *= 2
		else:
			c = k
			if (n - tot) % c == 0:
				count += (n - tot) // c
			else:
				count += (n - tot) // c + 1
			break
	print(count)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n - 1)
	else:
		l = len('{:0b}'.format(k))
		x = 2 ** l
		ans = (n - x) // k if (n - x) % k == 0 else (n - x) // k + 1
		print(ans + l)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	complete = 1
	h = 0
	if k == 1:
		print(n - 1)
	else:
		x = math.log2(k)
		if k - 2 ** math.floor(x) > 0:
			h = math.floor(x) + 1
		else:
			h = math.floor(x)
		t = n - 2 ** h
		if t > 0:
			if t % k == 0:
				h += t // k
			else:
				h += t // k + 1
		print(h)


import sys

def solve(mas):
	s = [int(i) for i in sys.stdin.readline().split()]
	(n, k) = (s[0], s[1])
	count = 1
	hours = 0
	while count < n:
		if mas[hours] < k and hours < 62:
			count += mas[hours]
		elif (n - count) % k == 0:
			hours += (n - count) // k
			print(hours)
			return
		else:
			hours += (n - count) // k + 1
			print(hours)
			return
		hours += 1
	print(hours)
t = int(sys.stdin.readline())
mas = [2 ** i for i in range(62)]
while t > 0:
	t -= 1
	solve(mas)


import sys
from collections import Counter
import math
import bisect
import heapq
from itertools import combinations
from itertools import permutations
from collections import defaultdict
from collections import Counter
num_cases = int(sys.stdin.readline().strip())
for case in range(1, num_cases + 1):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	computer = N - 1
	if computer == 0:
		print(0)
	else:
		signal = 0
		limit = 0
		for i in range(100):
			if pow(2, i) < K:
				continue
			else:
				signal = pow(2, i) - 1
				limit = i
				break
		if computer <= signal:
			for i in range(100):
				computer -= pow(2, i)
				if computer <= 0:
					print(i + 1)
					break
		else:
			(mock, namuji) = divmod(computer - signal, K)
			if namuji == 0:
				print(mock + limit)
			else:
				print(mock + 1 + limit)


import sys, os, io
import math
from collections import defaultdict

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

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	(n, k) = li()
	times = 0
	done = 1
	while 1 << times < n and 1 << times <= k:
		done = 1 << times
		times += 1
	if 1 << times >= n:
		print(times)
	else:
		val = (n - (1 << times) + k - 1) // k
		print(val + times)
t = 1
t = ii()
for _ in range(t):
	solve()


import sys, math
input = sys.stdin.readline
INF = int(1000000000.0) + 7

def solve():
	(n, k) = map(int, input().split())
	ans = 0
	cur = 1
	while cur <= k:
		if cur >= n:
			return ans
		ans += 1
		cur *= 2
	return ans + (n - cur + k - 1) // k
t = int(input())
while t:
	t -= 1
	print(solve())


import math

def next_two_degree(x):
	x -= 1
	x |= x >> 1
	x |= x >> 2
	x |= x >> 4
	x |= x >> 8
	x |= x >> 16
	x |= x >> 32
	x |= x >> 64
	return x + 1
n = int(input())
pair_list = []
for _ in range(n):
	pair_list.append(list(map(int, input().split())))
for item in pair_list:
	n = item[0]
	k = item[1]
	z = int(math.log2(next_two_degree(k)))
	if (n - 2 ** z) % k == 0:
		print(z + (n - 2 ** z) // k)
	else:
		print(z + (n - 2 ** z) // k + 1)


import bisect as bf
l = []
ma = 1
while ma <= 1e+18:
	l.append(ma)
	ma = ma * 2
l.append(ma)
t = int(input())
for dalskjd in range(t):
	(n, k) = [int(i) for i in input().split()]
	m = bf.bisect_left(l, k)
	if l[m] != k:
		m = m - 1
	std = 2 ** (m + 1)
	if n < std:
		count = bf.bisect_left(l, n)
	else:
		count = m + 2 + (n - std - 1) // k
	print(count)


t = int(input())
cc = [2 ** x for x in range(63)]

def cal_r0(x):
	for i in range(63):
		if x < cc[i]:
			return i - 1
for i in range(t):
	(n, k) = map(int, input().split(' '))
	if k == 1:
		print(n - 1)
	else:
		r0 = cal_r0(k)
		if 2 ** r0 == k:
			if n > 2 ** r0:
				if (n - 2 ** r0) % k == 0:
					r1 = int((n - 2 ** r0) // k)
				else:
					r1 = int((n - 2 ** r0) // k) + 1
				print(r0 + r1)
			else:
				print(r0)
		elif n > 2 ** (r0 + 1):
			if (n - 2 ** (r0 + 1)) % k == 0:
				r1 = int((n - 2 ** (r0 + 1)) // k)
			else:
				r1 = int((n - 2 ** (r0 + 1)) // k) + 1
			print(r0 + 1 + r1)
		else:
			print(r0 + 1)


import math
T = int(input())
for ttt in range(T):
	arr = input().split(' ')
	n = int(arr[0])
	k = int(arr[1])
	t1 = int(math.log(k, 2))
	if 2 ** t1 > k:
		t1 -= 1
	t2 = 2 ** (t1 + 1)
	t3 = n - t2
	res = t1 + 1
	res += t3 // k
	if t3 % k != 0:
		res += 1
	print(res)


p = int(input())
for _ in range(p):
	(n, k) = input().split()
	t = (len(k) - 1) // 3 * 10
	m = 2 ** t
	n = int(n)
	k = int(k)
	while m <= k and m < n:
		m *= 2
		t += 1
	if n > m:
		t += (n - m - 1) // k + 1
	print(t)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = 0
	if k == 1:
		print(n - 1)
	else:
		x = int(math.log(k, 2))
		if 2 ** x > k:
			x -= 1
		n = n - 2 ** (x + 1)
		h = x + 1 + n // k + (n % k != 0)
		print(h)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = [int(w) for w in input().split()]
	l = 0
	p2 = 1
	while p2 <= k:
		p2 *= 2
		l += 1
	p2 //= 2
	l -= 1
	r = k - p2

	def maxp(n):
		p = 1
		ct = 0
		while p < n:
			p *= 2
			ct += 1
		return ct
	if n <= 2 ** (l + 1):
		print(maxp(n))
		continue
	n -= 2 ** (l + 1)
	print((n - 1) // k + 1 + l + 1)


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():
	(a, b) = r()
	a -= 1
	c = 0
	n = 1
	while a > 0 and n <= b:
		c += 1
		a -= n
		n *= 2
	if a > 0:
		c += ceil_(a, b)
	print(c)
for _ in ' ' * ii():
	solve()


import bisect, math
t = [0 for i in range(64)]
for i in range(64):
	t[i] = 1 << i
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))

	def fun():
		if n == 1:
			return 0
		if k == 1:
			return n - 1
		i = bisect.bisect(t, k)
		if t[i] != k:
			i -= 1
		if t[i] * 2 >= n:
			j = bisect.bisect(t, n) - 1
			if t[j] == n:
				return j
			return j + 1
		return i + 1 + (n - t[i] * 2 + k - 1) // k
	print(fun())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	time = 0
	count = 1
	while count < k and count + min(count, k) <= n:
		count += min(count, k)
		time += 1
	time += (n - count) // k + ((n - count) % k != 0)
	print(time)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	c = 1
	s = 0
	while c < k:
		c *= 2
		s += 1
	n -= c
	if n % k == 0:
		print(s + n // k)
	else:
		print(s + n // k + 1)


import sys
input = sys.stdin.readline

def iinput():
	return int(input())

def sinput():
	return input().rstrip()

def i0input():
	return int(input()) - 1

def linput():
	return list(input().split())

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

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

def li0input():
	return list(map(lambda x: int(x) - 1, input().split()))

def mi0input():
	return map(lambda x: int(x) - 1, input().split())
INF = 10 ** 20
MOD = 1000000007

def solve(n, k):
	ctr = 0
	tmp = 1
	while tmp < k:
		if tmp >= n:
			return ctr
		ctr += 1
		tmp *= 2
	ctr += max(0, (n - tmp + k - 1) // k)
	return ctr
t = iinput()
for _ in [0] * t:
	(n, k) = liinput()
	ans = solve(n, k)
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())

def pow(n, k):
	if k == 0:
		return 1
	elif k == 1:
		return n
	if k % 2 == 0:
		return pow(n, k // 2) ** 2
	else:
		return pow(n, k - 1) * n
cache = [pow(2, i) for i in range(60)]

def solve(n, k):
	ret = 0
	s = 0
	while 2 ** s <= k:
		ret += 1
		n -= cache[s]
		s += 1
	ret += n // k
	if n % k != 0:
		ret += 1
	return ret
while t:
	t -= 1
	(n, k) = map(int, input().split())
	print(solve(n - 1, k))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, functools, copy, statistics
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()
import time
for _ in range(I()):
	(n, k) = LI()
	n -= 1
	x = k.bit_length()
	a = 2 ** x - 1
	ans = 0
	if a < n:
		ans += x
		b = n - a
		if b % k == 0:
			ans += b // k
		else:
			ans = ans + b // k + 1
	else:
		b = n.bit_length()
		ans += b
	print(ans)


import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
	(n, k) = map(int, stdin.readline().split())
	ntime = (k - 1).bit_length()
	nend = 2 ** ntime
	rem = n - nend
	if rem <= 0:
		ans = ntime
	else:
		ans = ntime + (rem + k - 1) // k
	ANS.append(str(ans))
print('\n'.join(ANS))


t = int(input())
for i in range(t):
	read = input().split()
	h = int(read[0])
	p = int(read[1])
	print(p.bit_length() + (h - 2 ** p.bit_length() - 1) // p + 1)


l = [2 ** i for i in range(61)]
for _ in range(int(input())):
	(n, k) = map(int, input().strip().split())
	if k == 1:
		print(n - 1)
	else:
		a = 0
		for i in range(61):
			if k <= l[i]:
				a = i
				break
		n -= l[a]
		if n > 0:
			a += n // k + min(n % k, 1)
		print(a)


nums = [2 ** i for i in range(100)]
for i in range(int(input())):
	(n, k) = map(int, input().split())
	i = 0
	a = 1
	for j in range(100):
		if nums[j] > k:
			i = j
			a = nums[i]
			break
	c = 0
	if (n - a) % k:
		c += 1
	ans = c + i + (n - a) // k
	print(ans)


import math

def complog(n):
	(k, count) = (0, 1)
	while True:
		if count >= n:
			return k
		else:
			k += 1
			count = 1 << k
n = int(input())
for i in range(n):
	(a, b) = [int(i) for i in input().split()]
	k = complog(b)
	sum = 1 << k
	print((a - sum + b - 1) // b + k)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	if n == 1:
		print(0)
	elif k == 1:
		print(n - 1)
	else:
		k_power = len(bin(k)) - bin(k).find('1') - 1
		n_power = len(bin(n)) - bin(n).find('1') - 1 if n & n - 1 == 0 else len(bin(n)) - bin(n).find('1')
		hrs = min(k_power + 1, n_power)
		rest = n - 2 ** hrs
		if rest > 0:
			rest_hrs = rest // k
			hrs += rest_hrs
			if rest - rest_hrs * k != 0:
				hrs += 1
		print(hrs)


def solve():
	(n, k) = map(int, input().split())
	z = 1
	time = 0
	while n > z and z <= k:
		z *= 2
		time += 1
	if z < n:
		time += (n - z + k - 1) // k
	print(time)
for i in range(int(input())):
	solve()


import math
n = int(input())
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	counter = 1
	ans = 0
	if a == 1:
		print(0)
		continue
	while counter <= b and counter != a:
		counter += counter
		ans += 1
	if counter >= a:
		print(ans)
	else:
		rem = a - counter
		ab = rem % b
		if ab == 0:
			print(ans + (rem - ab) // b)
		else:
			print(ans + (rem - ab) // b + 1)


from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
import os
import sys
from itertools import *
from io import BytesIO, IOBase
import math
import bisect
from math import inf
import random

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():
	t = 1
	t = int(input())
	for _ in range(1, t + 1):
		(n, k) = sep()
		if n == 1:
			print(0)
			continue
		p = 1
		ans = 0
		while p <= k:
			if p >= n:
				print(ans)
				break
			p *= 2
			ans += 1
		else:
			n -= p
			ans += (n + k - 1) // k
			print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


from math import ceil

def solve():
	(n, k) = map(int, input().split())
	c = 1
	ans = 0
	while c < k:
		c *= 2
		ans += 1
	if c < n:
		ans += (n - c + k - 1) // k
	return ans
for _ in range(int(input())):
	print(solve())


import sys, os
from io import BytesIO, IOBase
import bisect
import heapq
from collections import deque
from collections import Counter

def main():
	for _ in range(read()):
		(n, k) = read()
		(count, sums) = (0, 1)
		current = 0
		if k == 1:
			print(n - 1)
			continue
		while sums < k:
			sums *= 2
			count += 1
		n = n - sums
		if n <= 0:
			print(count)
			continue
		t = 0
		if n % k == 0:
			t = 0
		else:
			t = 1
		count += n // k + t
		print(count)
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 memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

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

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def read(void=None):
	value = list(map(int, input().split()))
	if len(value) == 1:
		return value[0]
	return value
main()


from sys import stdin, stdout
test_cases = int(stdin.readline())
for _ in range(int(test_cases)):
	(computers, cables) = map(int, stdin.readline().strip().split())
	comp_done = 1
	hours = 0
	while comp_done <= cables:
		comp_done *= 2
		hours += 1
	rest_hours = (computers - comp_done) // cables
	hours = hours + rest_hours
	if (computers - comp_done) % cables != 0:
		hours += 1
	print(hours)


def fun():
	n = int(input())
	for i in range(n):
		(n, k) = map(int, input().split())
		bad = 1
		good = n - 1
		ans = 0
		while bad <= k and good > 0:
			good -= bad
			bad += bad
			ans += 1
		if good > 0:
			ans += (good + k - 1) // k
		print(ans)
fun()


import math
t = int(input())
n = []
k = []
for i in range(t):
	val = input().split()
	n.append(int(val[0]))
	k.append(int(val[1]))
for i in range(t):
	numUpdates = 1
	hours = 0
	n[i] = n[i] - 1
	while n[i] > 0:
		if numUpdates >= k[i]:
			temp = n[i] // k[i]
			if n[i] % k[i] != 0:
				temp = temp + 1
			hours = hours + temp
			n[i] = 0
		else:
			n[i] = n[i] - numUpdates
			numUpdates = 2 * numUpdates
			hours = hours + 1
	print(hours)


import sys
import math
from fractions import Fraction
input = sys.stdin.readline
t = int(input())
while t > 0:
	s = [int(x) for x in input().split(' ')]
	n = s[0]
	k = s[1]
	p = k
	m = 0
	while p > 0:
		m += 1
		p = p >> 1
	m -= 1
	sat = 2 ** (m + 1)
	if n >= sat:
		ans = m + 1
		ans += math.ceil(Fraction(n - sat, k))
	else:
		p = n
		ans = 0
		while p > 0:
			ans += 1
			p = p >> 1
		ans -= 1
		if n > 2 ** ans:
			ans += 1
	print(ans)
	t -= 1


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = 0
	u = 1
	while u < k:
		u += u
		a += 1
	a += (n - u + k - 1) // k
	print(a)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
import math
import heapq
import bisect
import collections
BUFSIZE = 8192
inf = float('inf')

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))
get = lambda : sys.stdin.readline().rstrip('\r\n')
MOD = 1000000007
import math
for _ in range(int(get())):
	(n, k) = map(int, get().split())
	i = 1
	ans = 0
	while i <= k and i < n:
		i = i * 2
		ans += 1
	if i < n:
		ans += (n - i + k - 1) // k
	print(ans)


def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, k) = readIntArr()
		n -= 1
		ans = 0
		perhour = 1
		while perhour < k and n > 0:
			n -= perhour
			perhour = min(k, perhour * 2)
			ans += 1
		if n > 0:
			ans += (n + k - 1) // k
		allans.append(ans)
	multiLineArrayPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

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

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(i1, j1, i2, j2):
	print('! {} {} {} {}'.format(i1, j1, i2, j2))
	sys.stdout.flush()
inf = float('inf')
from math import gcd, floor, ceil
import math
for _abc in range(1):
	main()


from math import ceil
T = int(input())
ANS = []
for _ in range(T):
	(N, K) = map(int, input().split())
	ans = 0
	cur = 1
	while cur < K:
		cur *= 2
		ans += 1
	if cur < N:
		ans += (N - cur + K - 1) // K
	ANS.append(ans)
for ans in ANS:
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	print(k.bit_length() + (n - 2 ** k.bit_length() - 1) // k + 1)


import bisect
import math
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 __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 __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, k) = map(int, input().split())
	ans = 0
	p = 1
	f = 1
	n -= 1
	while n > 0 and p <= k:
		n -= p
		p <<= 1
		ans += 1
	ans += (n + k - 1) // k
	print(ans)
t = 1
t = int(input())
for i in range(t):
	solve(i + 1)


import sys
readline = sys.stdin.readline
N = int(readline())
for i in range(N):
	(N, K) = map(int, readline().split())
	c = 1
	ans = 0
	while c <= K and c < N:
		ans += 1
		c *= 2
	if c <= N:
		ans += (N - c + K - 1) // K
	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
mod = int(1000000000.0 + 7)
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

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 nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

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
d = []
primes = []
prim = [0] * (10 ** 5 + 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
mod = 1000000007
t = 1
t = I()
for _ in range(t):
	(n, k) = lint()
	n -= 1
	res = 1
	cnt = 0
	while n > 0 and res <= k:
		n = max(0, n - res)
		cnt += 1
		res *= 2
	if res * 2 > k:
		res = k
	if n > 0:
		cnt += n // res
		if n % res:
			cnt += 1
	print(cnt)


import math
t = int(input())
for i in range(t):
	read = input().split()
	n = int(read[0])
	k = int(read[1])
	exp = k.bit_length()
	left = (n - 2 ** exp - 1) // k + 1
	print(exp + left)


def solve(comp, cabl):
	time = 0
	now = 1
	while now < comp and now < cabl:
		now *= 2
		time += 1
	return time + (comp - now + cabl - 1) // cabl
n = int(input())
for _ in range(n):
	(comp, cabl) = map(int, input().split())
	print(solve(comp, cabl))


t = int(input())

def f(n, k):
	if n == 1:
		return 0
	elif n == 2:
		return 1
	prev = 2
	h = 1
	while prev < n:
		d = min(k, prev)
		if prev > k:
			rest = n - prev
			ans = rest // k
			if rest % k != 0:
				ans += 1
			h += ans
			break
		prev += d
		h += 1
	return h
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	print(f(n, k))


import math as m
import itertools

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

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

def solve():
	(n, k) = map(int, input().split())
	f = 1
	cout = 0
	while f <= k and f < n:
		f *= 2
		cout += 1
	if f < n:
		cout += (n - f + k - 1) // k
	print(cout)
for _ in range(int(input())):
	solve()


import math
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	answer = 0
	(n, k) = map(int, input().split())
	temp = 1
	while temp < k:
		temp <<= 1
		answer += 1
	if n > temp:
		n -= temp
		answer += (n + k - 1) // k
	print(answer)


import math
for test in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n == 1:
		print(0)
	elif k == 1:
		print(n - 1)
	else:
		ans = 1
		nos = 2
		while nos < k:
			nos *= 2
			ans += 1
		rem = n - nos
		ans += rem // k
		if rem % k != 0:
			ans += 1
		print(ans)


import sys
import os
import math
import bisect
from collections import *
import heapq
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from itertools import *
from functools import *
import random
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
INF = float('inf')
MOD = 1000000007
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 solve():
	(n, k) = mul()
	if n == 1:
		print(0)
	elif k == 1:
		print(n - 1)
	else:
		ans = 0
		curr = 1
		while curr <= k:
			ans += 1
			curr *= 2
		rem = n - curr
		ans += rem // k
		if rem % k != 0:
			ans += 1
		print(ans)
t = 1
t = inp()
for _ in range(t):
	solve()


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n -= 1
	b = 1
	ans = 1
	summ = 1
	while b * 2 < k:
		b *= 2
		ans += 1
		summ += b
	n -= summ
	ans += n // k + int(bool(n % k))
	print(ans)


import math
import time
bs = [2 ** i for i in range(63)]
tests = int(input())
for _ in range(tests):
	t1 = time.time()
	(n, k) = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		ibs = int(math.log(k, 2))
		res = ibs
		m = 2 ** ibs
		while m < n:
			if m >= k:
				break
			else:
				m = min(bs[ibs + 1], n)
				ibs += 1
				res += 1
		t3 = time.time()
		if m < n:
			res += (n - m) // k + (1 if (n - m) % k else 0)
		print(res)
	t2 = time.time()


t = int(input())
for tt in range(t):
	(n, k) = map(int, input().split())
	ans = 0
	on = 1
	while on < k and on < n:
		on <<= 1
		ans += 1
	if on < n:
		rem = n - on
		if rem % k > 0:
			ans += 1
		ans += rem // k
	print(ans)


import math
number_tests = int(input(''))
for test in range(number_tests):
	count = 0
	list_input = input('').split()
	total_computers = int(list_input[0])
	total_cables = int(list_input[1])
	log = len(bin(total_cables)) - 3
	temp = total_computers - 2 ** log + (total_cables - 2 ** log)
	end = temp // total_cables + (temp % total_cables > 0)
	print(log + end)