You have two positive integers $a$ and $b$.

You can perform two kinds of operations:

$a = \lfloor \frac{a}{b} \rfloor$ (replace $a$ with the integer part of the division between $a$ and $b$)

$b=b+1$ (increase $b$ by $1$)

Find the minimum number of operations required to make $a=0$.


-----Input-----

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

The only line of the description of each test case contains two integers $a$, $b$ ($1 \le a,b \le 10^9$).


-----Output-----

For each test case, print a single integer: the minimum number of operations required to make $a=0$.


-----Examples-----

Input
6
9 2
1337 1
1 1
50000000 4
991026972 997
1234 5678
Output
4
9
2
12
3
1


-----Note-----

In the first test case, one of the optimal solutions is:

Divide $a$ by $b$. After this operation $a = 4$ and $b = 2$.

Divide $a$ by $b$. After this operation $a = 2$ and $b = 2$.

Increase $b$. After this operation $a = 2$ and $b = 3$.

Divide $a$ by $b$. After this operation $a = 0$ and $b = 3$.

Difficulty: EASY
Tags: Number theory

Complete search

Mathematics

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
def Sort(sub_li):
	return sorted(sub_li, key=lambda x: x[1])
import math
n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	a = int(p[0])
	b = int(p[1])
	ans = 0
	if a == 1:
		if b == 1:
			print(2)
		else:
			print(1)
	else:
		ans1 = 1000000000000000000000000000000000000
		if b == 1:
			b += 1
			ans += 1
		M = 0
		for j in range(b, b + 100):
			b = j
			tot = M
			A = a
			M += 1
			while A > 0:
				A = A // b
				tot += 1
			ans1 = min(ans1, ans + tot)
		print(ans1)


def fun(a, b):
	stp = 0
	while a > b:
		a //= b
		stp += 1
	if b == a:
		stp += 2
	else:
		stp += 1
	return stp

def solve():
	(a, b) = map(int, input().split())
	if b > a:
		return 1
	if b == a:
		return 2
	ans = 0
	if b == 1:
		ans += 1
		b += 1
	ret = ans + fun(a, b)
	i = 1
	while True:
		ret2 = ans + i + fun(a, b + i)
		if ret2 > ret:
			return ret
		ret = ret2
		i += 1
	return ret
for _ in range(int(input())):
	print(solve())


testcase = int(input())
for i in range(testcase):
	(a, b) = [int(x) for x in input().split()]
	lst = []
	if b == 1:
		for j in range(1, 10):
			i = 1
			while (b + j) ** i <= a:
				i += 1
			lst.append(i + j)
	else:
		for j in range(10):
			i = 1
			while (b + j) ** i <= a:
				i += 1
			lst.append(i + j)
	print(min(lst))


for t in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	A = a
	B = b
	if b < 2:
		b += 1
		count += 1
	while a > 0:
		a //= b
		count += 1
		if a == b:
			b += 1
			count += 1
	count2 = count
	for j in range(1, count2):
		b = B + j
		a = A
		count2 = j
		while a > 0:
			count2 += 1
			a //= b
			if a == b:
				b += 1
				count2 += 1
		count = min(count, count2)
	print(count)


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	operacoes = math.inf
	for i in range(50):
		if b + i <= 1:
			continue
		aux = i
		c = a
		while c != 0:
			c = math.floor(c // (b + i))
			aux += 1
		if operacoes > aux:
			operacoes = aux
	print(operacoes)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	v = round(num)
	if abs(num - v) <= 10 ** (-10):
		return v
	return num
from math import floor, log, ceil

def solve(a, b):
	if b > a:
		return 1
	if b >= 10001:
		return floor(log(a, b)) + 1
	w = 0
	if b == 1:
		b += 1
		w += 1
	minn = float('inf')
	m = -1
	for i in range(b, 10001):
		val = floor(exact(log(a, i))) + i - b + 1
		if val < minn:
			minn = val
			m = i
	return minn + w
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	print(solve(a, b))


def minimum(value_a: int, value_b: int, optimal: int=float('inf')) -> int:
	for candidate in range(max(2, value_b), value_b + 30):
		(steps, trial) = (0, value_a)
		while trial:
			(trial, steps) = (trial // candidate, steps + 1)
		optimal = min(optimal, steps + candidate - value_b)
	return optimal if value_a else 0

def read_input(filename: str=None) -> None:
	from sys import stdin
	stdin = open(filename) if filename else stdin
	cases = int(stdin.readline())
	while cases:
		cases = cases - 1
		(value_a, value_b) = tuple(map(int, stdin.readline().split()))
		print(minimum(value_a, value_b))

def main():
	read_input()
main()


def func(a, b):
	c = 0
	if b == 1:
		return 10 ** 10
	while a != 0:
		a = a // b
		c += 1
	return c
t = int(input())
while t:
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	ans = 0
	while func(a, b) - func(a, b + 1) >= 1:
		b += 1
		ans += 1
	print(ans + func(a, b))
	t -= 1


def log(a, b):
	logVal = 0
	while a >= b:
		a //= b
		logVal += 1
	return logVal

def solve(a, b):
	if a < b:
		return 1
	if a == b:
		return 2
	if b == 1:
		b += 1
		startOpsCount = 1
	else:
		startOpsCount = 0
	opsCount = startOpsCount + log(a, b) + 1
	minOps = opsCount
	while startOpsCount < minOps:
		b += 1
		startOpsCount += 1
		opsCount = startOpsCount + log(a, b) + 1
		minOps = min(opsCount, minOps)
	return minOps
t = int(input())
for tc in range(t):
	(a, b) = map(int, input().split())
	result = solve(a, b)
	print(result)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	k = 0
	if a < b or a == b:
		if a < b:
			k = k + 1
		if a == b:
			k = k + 2
	else:
		if b == 1:
			k = k + 1
			b = b + 1
		b1 = b
		suu = 0
		su1 = 1
		su2 = 2
		su3 = 3
		su4 = 4
		su5 = 5
		su6 = 6
		while b1 <= a:
			b1 = b1 * b
			suu = suu + 1
		b1 = b + 1
		while b1 <= a:
			b1 = b1 * (b + 1)
			su1 = su1 + 1
		b1 = b + 2
		while b1 <= a:
			b1 = b1 * (b + 2)
			su2 = su2 + 1
		b1 = b + 3
		while b1 <= a:
			b1 = b1 * (b + 3)
			su3 = su3 + 1
		b1 = b + 4
		while b1 <= a:
			b1 = b1 * (b + 4)
			su4 = su4 + 1
		b1 = b + 5
		while b1 <= a:
			b1 = b1 * (b + 5)
			su5 = su5 + 1
		b1 = b + 6
		while b1 <= a:
			b1 = b1 * (b + 6)
			su6 = su6 + 1
		k = k + min(suu, su1, su2, su3, su4, su5, su6)
		k = k + 1
	print(k)


import time

def ass(a, b):
	print(f'Assertion error: {a} != {b}' if a != b else 'OK')

def number():
	return int(input())

def numbers():
	return [int(item) for item in input().split()]

def word():
	return input()

def words():
	return [item for item in input().split()]

def dump(lst):
	for (i, item) in enumerate(lst):
		print(i, item)

def binsearch(arr, a, b):
	m = (a + b) // 2
	if a >= b:
		return a - 1 if arr[a] == 0 else a
	return binsearch(arr, a, m - 1) if arr[m] == 0 else binsearch(arr, m + 1, b)

def gcd(x, y):
	return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)
cache = {}

def dp(a, b):
	level = 0
	if b == 2 and a > 3:
		b += 1
		level = 1
	if b == 1 and a > 3:
		b += 2
		level = 2
	queue = [[a, b]]

	def save(a, b):
		q2.append([a, b])
	while True:
		q2 = []
		level += 1
		for (a, b) in queue:
			if a < b:
				return level
			save(a // b, b)
			save(a, b + 1)
		queue = q2
for i in range(number()):
	(a, b) = numbers()
	print(dp(a, b))


for x in range(int(input())):
	(a, b) = map(int, input().split(' '))
	steps = 0
	counter = 0
	if b == 1:
		steps += 1
		b += 1
		counter += 1
	arr = []
	while True:
		c = a
		while c != 0:
			c //= b
			steps += 1
		b += 1
		counter += 1
		arr.append(steps)
		steps = counter
		try:
			if arr[-1] > arr[-2]:
				break
		except IndexError:
			continue
		if b <= a:
			continue
		else:
			break
	print(min(arr))


t = int(input())
while t:
	(a, b) = list(map(int, input().split()))
	ans = 40
	for i in range(32):
		if b == 1:
			b += 1
			continue
		count = 0
		temp = a
		while temp != 0:
			count += 1
			temp //= b
		b += 1
		ans = min(ans, count + i)
	print(ans)
	t -= 1


for i in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 2147483646
	for i in range(35):
		if b == 1 and i == 0:
			continue
		count = i
		c = a
		while c:
			c = c // (b + i)
			count += 1
		ans = min(ans, count)
	print(ans)


import math
tests = int(input())
for i in range(tests):
	(a, b) = map(int, input().split())
	operations = 0
	while a != 0:
		operations += 1
		if b == 1:
			b += 1
			continue
		exp1 = math.log(a, b)
		exp2 = math.log(a, b + 1) + 1
		if exp1 < exp2:
			a = a // b
		else:
			b += 1
	print(operations)


def div(a, b):
	s = 0
	while a >= b:
		a = a // b
		s += 1
	return s

def ad(a, b):
	total = 0
	if b == 1:
		b += 1
		total += 1
	m = div(a, b)
	mmm = div(a, b)
	for i in range(b + 1, m + b):
		if mmm > i - b + div(a, i):
			mmm = i - b + div(a, i)
	total += mmm + 1
	return total
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(ad(a, b))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split(' '))
	if a < b:
		print('1')
	elif a == b:
		print('2')
	else:
		min = 999999999
		for i in range(0, 31):
			(a_, b_) = (a, b)
			if b_ == 1:
				b_ += 1
			cnt = 0 if b != 1 else 1
			cnt += i
			b_ += i
			while a_ != 0:
				a_ = a_ // b_
				cnt += 1
			if cnt < min:
				min = cnt
		print(min)


prevn = 50

def divide(a, b):
	n = 0
	while a != 0:
		a = a // b
		n += 1
	return n

def operation(a, b):
	localb = b
	global prevn
	prevn = 50
	if localb == 1:
		localb += 1
	while True:
		x = a
		n = divide(x, localb)
		if n + localb - b <= prevn:
			prevn = n + localb - b
			localb += 1
		else:
			return prevn

def main():
	n = int(input())
	for i in range(n):
		x = [int(j) for j in input().split()]
		print(operation(x[0], x[1]))
main()


import sys
input = sys.stdin.readline

def f(a, b):
	c = 0
	while b < 2:
		b += 1
		c += 1
	while a > 0:
		a //= b
		c += 1
	return c
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(min((i + f(a, b + i) for i in range(100))))


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

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

def print_list(l):
	print(''.join(map(str, l)))
for _ in range(N()):
	(a, b) = RL()
	ans = float('inf')
	s = 0
	if b == 1:
		s += 1
		b += 1
	while 1:
		now = s
		aa = a
		while aa:
			aa //= b
			now += 1
		if now > ans:
			break
		ans = now
		s += 1
		b += 1
	print(ans)


for s in [*open(0)][1:]:
	(a, b) = map(int, s.split())
	n = b
	r = 23
	while n - b < r:
		m = a
		i = 0
		if ~-n:
			while m:
				i += 1
				m //= n
			r = min(r, n - b + i)
		n += 1
	print(r)


import sys
inp = sys.stdin.readline
for _ in range(int(inp())):
	(a, b) = map(int, inp().split())
	ans = sys.maxsize
	for i in range(40):
		if b == 1 and i == 0:
			continue
		cnt = i
		now = a
		while now:
			now //= b + i
			cnt += 1
		ans = min(ans, cnt)
	print(ans)


import math

def min_counts(a, b):
	count = 0
	while a > 0:
		if b == 1 or math.log(a, b) > 1 + math.log(a, b + 1):
			b += 1
			count += 1
		else:
			a = int(a / b)
			count += 1
	return count
t = int(input())
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	print(min_counts(a, b))


def count(a, b):
	r = 0
	while a > 0:
		a //= b
		r += 1
	return r

def solve(a, b):
	res = 10 ** 9
	d = 0 if b > 1 else 1
	while d < res:
		res = min(res, count(a, b + d) + d)
		d += 1
	return res
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print(solve(a, b))


T = int(input())
for t in range(T):
	(a, b) = [int(i) for i in input().split()]
	cnt = 0
	if b == 1:
		b += 1
		cnt += 1
	flag = 1
	A = a
	CNT = cnt
	index = 0
	B = b
	ans = 1000000000000
	while flag == 1:
		cnt = CNT + index
		a = A
		b = B + index
		while a > 0:
			a = a // b
			cnt += 1
		if cnt <= ans:
			ans = cnt
			index += 1
		else:
			flag = 0
	print(ans)


def solve():
	(a, b) = list(map(int, input().split()))
	if b > a:
		print(1)
		return
	if b == a:
		print(2)
		return
	dif = a - b
	lol = 0
	plus_b = 0
	min_ans = 10 ** 9 + 10
	if b == 1:
		b += 1
		plus_b += 1
	while a // b > 0:
		a1 = a
		mem = 0
		while a1 > 0:
			a1 //= b
			mem += 1
		min_ans = min(min_ans, plus_b + mem)
		b += 1
		plus_b += 1
		if min_ans <= plus_b:
			break
	print(min_ans)
t = int(input())
for q in range(t):
	solve()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = float('inf')
	i = 0
	while i * i <= a:
		if b == 1 and i == 0:
			i += 1
			continue
		c = a
		count = i
		while c:
			c = c // (b + i)
			count += 1
		ans = min(ans, count)
		i += 1
	print(ans)


def solve(a, b):
	c = 0
	while a != 0:
		if b == 0:
			b += 2
			c += 2
		elif b == 1:
			b += 1
			c += 1
		elif 1 + times(a, b + 1) <= times(a, b):
			b += 1
			c += 1
		else:
			return c + times(a, b)

def times(a, b, n=0):
	while a != 0:
		a = a // b
		n += 1
	return n
for t in range(int(input())):
	(a, b) = map(int, input().split())
	print(solve(a, b))


t = int(input())
for _ in range(t):
	(C, N) = map(int, input().split())
	minDays = float('inf')
	minFriends = max(2, N)
	maxFriends = max(N, 7)
	for numFriends in range(minFriends, maxFriends + 1):
		days = numFriends - N
		c = C
		while c > 0:
			c = c // numFriends
			days += 1
		days -= 1
		minDays = min(minDays, days)
	print(minDays + 1)


t = int(input())
for p in range(0, t):
	ab = input().split()
	a = int(ab[0])
	nota = a
	b = int(ab[1])
	notb = b
	result = 0
	all = []
	for i in range(0, 20):
		b = notb
		a = nota
		result = 0
		result += i
		b += i
		if notb == 1:
			b += 1
			result += 1
		while a > 0:
			a = int(a / b)
			result += 1
		all.append(result)
		if all[len(all) - 1] > all[len(all) - 2]:
			print(all[len(all) - 2])
			break


for T in range(int(input())):
	(a, b) = [int(p) for p in input().split()]
	ans = 100000
	if a < b:
		print(1)
	elif a == b:
		print(2)
	else:
		running = True
		best_yet = 10000000000
		i = 0
		if b == 1:
			i = 1
		while running:
			curr_div = b + i
			curr_ans = a
			j = 0
			while curr_ans > 0:
				curr_ans = curr_ans // curr_div
				j += 1
			if i + j > best_yet:
				running = False
			if i + j < best_yet:
				best_yet = i + j
			i += 1
		print(best_yet)


numTests = int(input())
output = []
import math

def getBest(c, d):
	counter = 0
	while True:
		counter += 1
		if c < d:
			c = 0
			break
		elif d == 1:
			d += 1
		elif c == d:
			d += 1
		else:
			c = math.floor(c / d)
	return counter
for i in range(numTests):
	info = input().split()
	a = int(info[0])
	b = int(info[1])
	best = getBest(a, b)
	i = 0
	while True:
		if getBest(a, b + i) + i < best:
			best = getBest(a, b + i) + i
		elif getBest(a, b + i) + i > best:
			break
		i += 1
	output.append(best)
for i in output:
	print(i)


def calc(a, b):
	if a == 1:
		return 10000000000.0
	i = 0
	while b > 0:
		b = b // a
		i += 1
	return i
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	ans = 0
	while calc(b, a) - calc(b + 1, a) >= 1:
		b += 1
		ans += 1
	print(ans + calc(b, a))


def get(a, b):
	ans = 0
	while a > 0:
		a = a // b
		ans += 1
	return ans
import math
t = 1
t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	if a == 1 and b == 1:
		print(2)
	elif b == 1:
		b += 1
		ans = 1
		while get(a, b) > get(a, b + 1):
			ans += 1
			b += 1
		print(ans + min(get(a, b), get(a, b + 1) + 1))
	else:
		ans = 0
		while get(a, b) > get(a, b + 1):
			b += 1
			ans += 1
		print(ans + min(get(a, b), get(a, b + 1) + 1))


def find():
	(a, b) = map(int, input().split())
	ans = 0
	a_save = a
	s = 0
	s1 = 0
	tmp = 0
	while not ans or tmp <= ans:
		ans = tmp
		if b == 1:
			b += 1
			s1 += 1
		while a > 0:
			a //= b
			s += 1
		tmp = s + s1
		b += 1
		s1 += 1
		s = 0
		a = a_save
	return ans
for i in range(int(input())):
	print(find())


t = int(input())
result = []
for i in range(t):
	j = 0
	(a, b) = list(map(int, input().split(' ')))
	minimum = float('inf')
	initialea = a
	if b == 1:
		count = [minimum]
		j = 1
	else:
		count = []
	while j <= minimum - 1:
		a = initialea
		countt = j
		while a // (j + b) != 0:
			countt += 1
			a = a // (j + b)
		countt += 1
		if countt < minimum:
			minimum = countt
		count.append(minimum)
		j += 1
	result.append(minimum)
for i in result:
	print(i)


import sys
import math
from itertools import permutations

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

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

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

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

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

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod
for _ in range(II()):
	(a, b) = MI()
	ans = 0
	if b == 1:
		ans += 1
		b += 1
	x = 0
	temp = a
	while temp != 0:
		x += 1
		temp //= b
	m = x + ans
	init = b
	for i in range(b, 30):
		x = i - init + ans
		temp = a
		while temp != 0:
			temp //= i
			x += 1
		m = min(m, x)
	print(int(m))


def get(a, b):
	if b == 1:
		return 1000000000
	cn = 0
	while a:
		a //= b
		cn += 1
	return cn
import math
test = int(input())
for t in range(test):
	(x, y) = map(int, input().split())
	ans = 1000000000
	for i in range(10000):
		k = get(x, y + i)
		ans = min(ans, i + k)
	print(ans)


def n_div(x, y):
	count = 0
	while x:
		x //= y
		count += 1
	return count
t = int(input())
for i in range(t):
	[a, b] = list(map(int, input().split(' ')))
	n_op = 0
	if b == 1:
		n_op = 1
	n_ini = n_div(a, b + n_op) + n_op
	temp = [n_ini]
	temp += [n_div(a, b + n_op + x) + x + n_op for x in range(1, n_ini)]
	print(min(temp))


def gen_solution(a, b):
	steps = 0
	if b == 1:
		return float('inf')
	while a > 0:
		a = a // b
		steps += 1
	return steps

def solve(a, b):
	s = 0
	prevSolution = float('inf')
	while True:
		solution = gen_solution(a, b) + s
		if solution > prevSolution:
			return prevSolution
		prevSolution = solution
		s += 1
		b += 1
t = int(input())
for j in range(t):
	(a, b) = [int(i) for i in input().split(' ')]
	print(solve(a, b))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 10000
	val = -1
	for d in range(max(2, b), b + 20):
		tmp = a
		cnt = d - b
		while tmp > 0:
			tmp //= d
			cnt += 1
		ans = min(ans, cnt)
	ans = min(ans, 22 - (d > a))
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	ans2 = 99999999999999999
	if b == 1:
		b += 1
		ans += 1
	ans1 = ans
	for i in range(20):
		k = a
		ans1 = ans
		while k != 0:
			ans1 += 1
			k = k // (b + i)
		ans2 = min(ans1 + i, ans2)
	print(ans2)


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	min_ = 1000000
	flag = 0
	c = 0
	b_init = b
	while c < 100:
		c += 1
		if b != 1:
			c1 = int(math.log(a, b))
			count1 = c1 + (b - b_init) + 1
			if pow(b, c1 + 1) == a:
				count1 += 1
			if min_ > count1:
				min_ = count1
		b += 1
	print(min_)


from sys import stdin, stdout, setrecursionlimit
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm, accumulate
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
setrecursionlimit(10 ** 9)
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return input()

def num():
	return int(input())

def L():
	return list(sp())

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

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

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

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

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

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def pmat2(A):
	for ele in A:
		for j in ele:
			print(j, end='')
		print()

def iseven(n):
	return n % 2 == 0

def seive(r):
	prime = [1 for i in range(r + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(r + 1):
		if prime[i]:
			for j in range(2 * i, r + 1, i):
				prime[j] = 0
	return prime
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	res = []
	for x in range(max(2, b), max(1001, b + 1)):
		cnt = x - b
		now = a
		while now:
			now //= x
			cnt += 1
		res.append(cnt)
	print(min(res))
endtime = time.time()


def cou(a, b):
	count = 0
	while a > 0:
		a = a // b
		count += 1
	return count
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c = 0
	if b == 1:
		b += 1
		c += 1
	ans = []
	for i in range(10):
		ans.append(cou(a, b + i) + c + i)
	print(min(ans))


def solve(a, b):
	b1 = b + (b == 1)
	ans = None
	while True:
		k = 0
		a1 = a
		while a1:
			a1 = a1 // b1
			k += 1
		if ans == None:
			ans = k + b1 - b
		elif ans >= k + b1 - b:
			ans = k + b1 - b
		else:
			return ans
		b1 += 1
for t in range(int(input())):
	(a, b) = map(int, input().split())
	print(solve(a, b))


def f(a, b):
	total = 0
	while a > 0:
		a //= b
		total += 1
	return total
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	best_ans = 10 ** 9
	for test in range(max(2, b), b + 30):
		best_ans = min(best_ans, test - b + f(a, test))
	print(best_ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	m = 0
	if b == 1:
		b += 1
		m += 1
	ans = perm = m
	temp = a
	while temp != 0:
		temp = temp // b
		m += 1
	low = m
	while ans <= m:
		temp = a
		ans = perm
		while temp != 0:
			temp = temp // b
			ans += 1
		if ans <= low:
			low = ans
		perm += 1
		b += 1
	print(low)


from sys import stdin
_input = stdin.readline
(_int, _range) = (int, range)

def solution():
	for _ in _range(_int(_input())):
		(a, b) = [_int(i) for i in _input().split()]
		degre = 1
		if b == 1 and a == 1:
			print(2)
			continue
		if b == 1:
			b += 1
			counter = 1
		else:
			counter = 0
		while a >= b ** degre:
			degre += 1
		m = degre + counter
		for i in _range(degre + 1):
			d = b + i
			ans = 1
			while a >= d ** ans:
				ans += 1
			if ans + i + counter < m:
				m = ans + i + counter
		print(m)
solution()


import sys
input = sys.stdin.readline
import math
t = int(input())
for f in range(t):
	(a, b) = map(int, input().split())
	ans = 1000000000
	for i in range(10000):
		temp = i
		check = b
		comp = a
		check += i
		if check == 1:
			continue
		while comp != 0:
			comp //= check
			temp += 1
		ans = min(ans, temp)
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	ans = 0
	count = 0
	temp = 0
	while a != 0:
		if a // b == 0:
			if ans == 0:
				ans += 1
			break
		if b == 1:
			b += 1
			count += 1
		temp = 0
		(c, d) = (a, b)
		while c != 0:
			temp += 1
			c = c // d
		if ans == 0:
			ans = temp + count
		elif temp + count > ans:
			break
		else:
			ans = temp + count
		b += 1
		count += 1
	print(ans)


import math

def calcAmount(a, b, c):
	count = c
	while a > 0:
		if b == 1:
			b += 1
			count += 1
		a = math.floor(a / b)
		count += 1
	return count
t = input()
l = []
for i in range(int(t)):
	st = input()
	(a, b) = st.split(' ')
	(a, b) = (int(a), int(b))
	c = 0
	numBefore = calcAmount(a, b, 0)
	numNow = calcAmount(a, b + 1, 1)
	while numBefore >= numNow:
		b += 1
		c += 1
		numBefore = numNow
		numNow = calcAmount(a, b, c)
	if numBefore < numNow:
		l.append(numBefore)
	else:
		l.append(numNow)
[print(x) for x in l]


for s in [*open(0)][1:]:
	(ao, ob) = map(int, s.split())
	solutions = []
	for i in range(ob, ob + 10):
		steps = i - ob
		b = i
		a = ao
		while a != 0:
			if a / b == a or a == b:
				steps += 1
				b += 1
			else:
				a = int(a / b)
				steps += 1
		solutions.append(steps)
	print(min(solutions))


import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
	(a, b) = map(int, stdin.readline().split())
	ans = float('inf')
	cnt = 0
	while cnt <= ans:
		A = a
		B = b + cnt
		tans = cnt
		if B != 1:
			while A > 0:
				tans += 1
				A //= B
			ans = min(ans, tans)
		cnt += 1
	ANS.append(ans)
print('\n'.join(map(str, ANS)))


def solve(a, b):
	res = 30
	for i in range(0, 32):
		if b + i == 1:
			continue
		c = 0
		tmp = a
		while tmp > 0:
			c += 1
			tmp = tmp // (b + i)
		res = min(res, i + c)
	return res
no_of_lines = int(input())
while no_of_lines:
	no_of_lines -= 1
	(a, b) = input().split(' ')
	print(solve(int(a), int(b)))


for k in range(int(input())):
	(n, d) = map(int, input().split())
	dp = [10 ** 18] * 1001
	op1 = 0
	j = 0
	if d == 1:
		j = 1
	for i in range(j, 1001):
		op1 = i
		d1 = d + i
		n1 = n
		while n1 != 0:
			n1 = n1 // d1
			op1 += 1
		dp[i] = op1
	print(min(dp))


def func(a, b):
	num_steps = 0
	if a < b:
		return 1
	elif a == b:
		return 2
	else:
		if b == 1:
			b += 1
			num_steps += 1
		if b > 31622:
			while pwr(a, b) > pwr(a, b + 1):
				b += 1
				num_steps += 1
			return num_steps + root(a, b)
		else:
			while pwr(a, b) > pwr(a, b + 1):
				b += 1
				num_steps += 1
			return num_steps + root(a, b)

def pwr(a, b):
	for pwr in range(2, 31, 1):
		if b ** pwr > a:
			return pwr

def root(a, b):
	for root in range(2, 31, 1):
		if a ** (1.0 / root) < b:
			return root

def main():
	t = int(input())
	a = [0] * t
	b = [0] * t
	for i in range(t):
		(a[i], b[i]) = [int(i) for i in input().split()]
	for i in range(t):
		print(func(a[i], b[i]))
main()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	m = 9999999
	while a != 0:
		if b == 1:
			b += 1
			ans += 1
		else:
			temp = a
			c = 0
			while a != 0:
				a //= b
				c += 1
			a = temp
			if m < ans + c:
				break
			m = min(m, ans + c)
			b += 1
			ans += 1
	print(m)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	N = int(input())
	for _ in range(N):
		(A, B) = list(map(int, input().split()))
		answer = math.inf
		for i in range(2, 40):
			x = A
			quant = 0
			i = max(i, B)
			while x != 0:
				x = int(x / i)
				quant += 1
			answer = min(quant + (i - B if i - B > 0 else 0), answer)
		print(answer)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	mn = -1
	start_count = 0
	if b == 1:
		start_count += 1
		b += 1
	while True:
		(curr_num, curr_count) = (a, start_count)
		while curr_num > 0:
			curr_num //= b
			curr_count += 1
		if mn == -1 or mn >= curr_count:
			mn = curr_count
			b += 1
			start_count += 1
		else:
			break
	print(mn)


for __ in range(int(input())):
	(a, b) = map(int, input().split())
	c = []
	(m, n) = (a, b)
	count = 0
	if n == 1:
		n = 2
		count = 1
	for _ in range(30):
		co = count + _
		(a, b) = (m, n + _)
		while a > 0:
			a //= b
			co += 1
		c.append(co)
	print(min(c))


from math import log
t = int(input())
while t != 0:
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	res = 0
	while a != 0:
		if b == 1 or log(a, b + 1) < log(a, b) - 1:
			b += 1
		else:
			a = a // b
		res += 1
	print(res)
	t -= 1


T = int(input())
for _ in range(T):
	(a, b) = [int(i) for i in input().split()]
	ans = 1000000000.0
	for i in range(60):
		(x, y) = (b + i, a)
		if x == 1:
			continue
		cnt = 0
		while y:
			cnt += 1
			y //= x
		ans = min(ans, cnt + i)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	ans = 31
	for i in range(30):
		curr = 0
		now = n
		while now and i + m > 1:
			curr += 1
			now //= i + m
		if i + m > 1:
			ans = min(ans, i + curr)
	print(ans)


from _testcapi import INT_MAX

def solve():
	(a, b) = map(int, input().split())
	ans = INT_MAX
	for i in range(30):
		n = a
		m = b + i
		y = 0
		if m == 1:
			continue
		while n != 0:
			n //= m
			y += 1
		ans = min(ans, y + i)
	print(ans)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	cnt2 = 0
	temp = b
	temp1 = a
	if b == 1:
		b = 2
	ans = float('inf')
	for i in range(0, 32):
		cnt1 = 0
		while a != 0:
			a = a // b
			cnt1 += 1
		ans = min(ans, cnt1 + cnt2)
		b += 1
		a = temp1
		cnt2 += 1
		if cnt1 > temp1:
			break
	if temp == 1:
		print(ans + 1)
	else:
		print(ans)


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)

def number_to_list(a):
	b = []
	while a >= 1:
		c = a % 10
		a = int(a / 10)
		b.append(c)
	return list(reversed(b))

def str_list_to_int_list(a):
	a = list(map(int, a))
	return a

def make_1d_array(n, inti=0):
	a = [inti for _ in range(n)]
	return a

def make_2d_array(n, m, inti=0):
	a = [[inti for _ in range(m)] for _ in range(n)]
	return a

def make_3d_array(n, m, k, inti=0):
	a = [[[inti for _ in range(k)] for _ in range(m)] for _ in range(n)]
	return a

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input()))
(t,) = I()
for t1 in range(t):
	(n, m) = I()
	if int(n / m) == 0:
		print(1)
	else:
		n1 = n
		m1 = m
		if m1 == 1:
			count = n + 1
		else:
			count = 0
			while n1 > 0:
				n1 = int(n1 / m1)
				count += 1
		for i in range(m1 + 1, 10 ** 9):
			n1 = n
			count1 = 0
			while n1 > 0:
				n1 = int(n1 / i)
				count1 += 1
			if count1 + i - m1 > count:
				break
			else:
				count = count1 + i - m1
		print(count)


import math
cases = int(input())
for i in range(cases):
	(a, b) = list(map(int, input().split()))
	count = 0
	while a:
		if a // b == 0 or (b > 1 and math.log(a // b, b) <= math.log(a, b + 1)):
			a //= b
		else:
			b += 1
		count += 1
	print(count)


t = int(input())
for t0 in range(t):
	(a, b) = [int(i) for i in input().split()]
	s = []
	k = 0
	if b == 1:
		k += 1
		b = 2
	for i in range(30):
		a0 = a
		k0 = k + i
		while a0 != 0:
			a0 = a0 // (b + i)
			k0 += 1
		s.append(k0)
	print(min(s))


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 10 ** 18
	c = int(math.sqrt(a)) + 1
	for i in range(b, c + 4):
		temp = i - b
		t = a
		while i > 1 and t > 0:
			t //= i
			temp += 1
		if i > 1:
			ans = min(ans, temp)
	if ans == 1e+18:
		ans = 0
		while a > 0:
			a //= b
			ans += 1
	print(ans)


n = int(input())
q = []
for i in range(n):
	q.append(list(map(int, input().strip().split())))
for x in q:
	a = x[0]
	b = x[1]
	mincount = 35
	for i in range(35):
		count = 0
		x = a
		y = b
		if y == 1:
			y += 1
			count += 1
		y = y + i
		count += i
		while x > 0:
			x = x // y
			count += 1
			if count > 35:
				break
		mincount = min(mincount, count)
	print(mincount)


def solve(a, b, m):
	moves = m
	while a != 0:
		a //= b
		moves += 1
	return moves
T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	base = b
	decreasing = True
	ans = 100000000000
	while decreasing:
		if b == 1:
			b += 1
		tmp = solve(a, b, b - base)
		if tmp > ans:
			decreasing = False
			ans = min(ans, tmp)
		else:
			ans = tmp
		b += 1
	print(ans)


def find_min(a, b):
	minimum = 0
	if b == 1:
		minimum += 1
		b += 1
	while a > 0:
		a //= b
		minimum += 1
	return minimum

def main():
	for _ in range(0, int(input())):
		str_input = list(input().split(' '))
		a = int(str_input[0])
		b = int(str_input[1])
		ret = find_min(a, b)
		minimum = 1 + find_min(a, b + 1)
		if ret < minimum:
			print(ret)
		else:
			aux = 2
			while minimum <= ret:
				ret = minimum
				minimum = aux + find_min(a, b + aux)
				aux += 1
			print(ret)
main()


T = int(input())
ans = ''
for _ in range(T):
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	t = 0
	if b == 1:
		b += 1
		t += 1
	r = t
	c = a
	while c > 0:
		c //= b
		r += 1
	while True:
		t += 1
		b += 1
		c = a
		r0 = 0
		while c > 0:
			c //= b
			r0 += 1
		if r > r0 + t:
			r = r0 + t
		if r0 <= 3:
			break
	ans += str(r) + '\n'
print(ans)


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	l = b
	ans = []
	z = 0
	if b < 2:
		b = 2
		z = 2 - b
	for i in range(b, b + 20):
		t = z
		p = a
		while p > 0:
			p = p // i
			t += 1
		ans.append(i - l + t)
	print(min(ans))


import sys

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

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

def input():
	return sys.stdin.readline().strip()
import math
for _ in range(int(input())):
	(a, b) = get_ints()
	count = 0
	mi = 10 ** 10
	if a == b and b == 1:
		print(2)
		continue
	if a == b:
		print(2)
		continue
	if a == 1:
		print(1)
		continue
	if b > a:
		print(1)
		continue
	while True:
		if b == 1:
			b += 1
			count += 1
			continue
		else:
			if b == 0:
				continue
			t = a - a % b
			if b > t:
				break
			k = round(math.log(t, b), 12)
			if k == math.ceil(k):
				k -= 1
				k += 2
				if k + count <= mi:
					mi = k + count
					b += 1
					count += 1
					continue
				else:
					break
			else:
				k = math.ceil(k)
				if k + count <= mi:
					mi = k + count
					b += 1
					count += 1
				else:
					break
	print(int(mi))


import math
t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split())
	if b > a:
		print(1)
	else:
		flag = False
		if b == 1:
			flag = True
			b += 1
		anss = 10000000000000
		ans = 0
		while True:
			poww = 1
			while math.floor(a / b ** poww) > 0:
				poww += 1
			if poww + ans <= anss:
				anss = poww + ans
				b += 1
				ans += 1
			else:
				break
		if flag:
			print(anss + 1)
		else:
			print(anss)


from math import log

def main():
	cases = int(input())
	ans_list = []
	for _ in range(cases):
		(a, b) = map(int, input().split(' '))
		count = 0
		if b == 1:
			b += 1
			count += 1
		while True:
			(meth_1, meth_2) = (0, 0)
			(t1, t2) = (a, a)
			while t1 > 0:
				t1 //= b
				meth_1 += 1
			while t2 > 0:
				t2 //= b + 1
				meth_2 += 1
			if meth_1 < meth_2 + 1:
				break
			b += 1
			count += 1
		ans_list.append(meth_1 + count)
	print('\n'.join(map(str, ans_list)))
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')
main()


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = math.inf
	c = 0
	for i in range(0, 31):
		if b == 1 and i == 0:
			continue
		c = i
		tmp = a
		while tmp != 0:
			tmp //= b + i
			c += 1
		ans = min(ans, c)
	print(ans)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	minimum = 0
	done = False
	counter_b = 0
	if b == 1:
		b += 1
		counter_b += 1
	while not done:
		aux = a
		counter = 0
		while aux > 0:
			counter += 1
			aux //= b
		counter += counter_b
		b += 1
		counter_b += 1
		if minimum == 0:
			minimum = counter
		elif counter > minimum:
			done = True
		else:
			minimum = counter
	print(minimum)


import math
for _ in range(int(input())):
	s = 0
	min = 9999
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	for i in range(b, b + 20):
		if i == 1:
			continue
		s1 = math.ceil(math.log(a, i)) + (i - b)
		if a // pow(i, math.ceil(math.log(a, i))) != 0:
			s1 += 1
		if s1 < min:
			min = s1
	print(min)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	p = []
	for j in range(10):
		c = 0
		k = m + j
		c += j
		o = n
		while o >= 1:
			if k == 1 or k == o:
				k += 1
				c += 1
			else:
				o = o // k
				c += 1
		p.append(c)
	print(min(p))


import sys
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
	(a, b) = map(int, input().split())
	res = 0
	trial = [(a, b)]
	cnt = 0
	while True:
		if res != 0:
			break
		cnt += 1
		nxt = []
		while trial:
			(x, y) = trial.pop()
			if x // y == 0:
				res = cnt
				break
			nxt.append((x // y, y))
			nxt.append((x, y + 1))
		trial = nxt
	print(res)


t = int(input())
for _ in range(t):
	ans = []
	got_answer = 0
	(a, b) = map(int, input().split())
	if a < b:
		ans.append(1)
	elif a == b:
		ans.append(2)
	else:
		for i in range(b, a + 2):
			if i != 1:
				times = i - b
				c = a
				while c != 0:
					c = c // i
					times += 1
				try:
					if ans[-1] >= times:
						ans.append(times)
					else:
						print(ans[-1])
						got_answer = 1
						break
				except IndexError:
					ans.append(times)
			else:
				pass
	if got_answer == 1:
		pass
	else:
		print(min(ans))


def findM(a, b):
	m = 0
	if b == 1:
		m += 1
		b += 1
	while a > 0:
		a //= b
		m += 1
	return m
for _ in range(0, int(input())):
	(a, b) = map(int, input().split())
	pm = findM(a, b)
	m = 1 + findM(a, b + 1)
	if pm < m:
		print(pm)
	else:
		s = 2
		while m <= pm:
			pm = m
			m = s + findM(a, b + s)
			s += 1
		print(pm)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	m = 1000000
	count = 0
	i = 0
	while i ** i <= a:
		if b == 1 and i == 0:
			i += 1
			continue
		count = i
		c = a
		while c > 0:
			c //= b + i
			count += 1
		m = min(count, m)
		i += 1
	print(m)


t = int(input())
for z in range(t):
	(m, n) = map(int, input().split())
	k = n
	ans = []
	while 1:
		i = 0
		if k == 1:
			k = k + 1
		while k ** i <= m:
			i = i + 1
		if len(ans) == 0:
			ans.append(i + k - n)
		elif ans[-1] < i + k - n:
			break
		else:
			ans.append(i + k - n)
		k = k + 1
	print(ans[-1])


import math
for t in range(int(input())):
	(a, b) = [int(k) for k in input().split()]
	if b > a:
		print(1)
	elif b == a:
		print(2)
	else:
		step = 0
		if b == 1:
			b += 1
			step += 1
		ans = int(math.log(a, b) + 1e-15) + 1 + step
		while b < a:
			b += 1
			step += 1
			if int(math.log(a, b) + 1e-15) + 1 + step <= ans:
				ans = int(math.log(a, b) + 1e-15) + 1 + step
			else:
				break
		print(ans)


from collections import deque
T = int(input())
visited = {}

def find_sol(a, b):
	global visited
	queue = deque([(a, b, 0)])
	while len(queue) != 0:
		n = queue.popleft()
		if n[0] == 0:
			return n[2]
		try:
			x = visited[n[0], n[1]]
			continue
		except KeyError:
			visited[n[0], n[1]] = 1
		queue.append((n[0] // n[1], n[1], n[2] + 1))
		queue.append((n[0], n[1] + 1, n[2] + 1))
	return -1
for i in range(T):
	(a, b) = map(int, input().rstrip().split(' '))
	print(find_sol(a, b))
	visited = {}


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	maxi = 100875875387278537
	for i in range(40):
		count = i
		temp = a
		if b == 1:
			b += 1
			count += 1
			continue
		while temp > 0:
			temp = int(temp / b)
			count += 1
		maxi = min(maxi, count)
		b += 1
	print(maxi)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	n = b
	r = 99
	while n - b < r:
		m = a
		i = 0
		if n > 1:
			while m:
				i += 1
				m //= n
			r = min(r, n - b + i)
		n += 1
	print(r)


def check(a, b):
	outer_counter = 0
	if b == 1:
		outer_counter += 1
		b += 1
	result = 35
	for i in range(31):
		temp_b = b + i
		zero = a
		inner_counter = i
		while zero != 0:
			zero = zero // temp_b
			inner_counter += 1
		result = min(result, inner_counter + outer_counter)
	print(result)
counter = int(input())
for i in range(counter):
	input_info = [int(i) for i in input().split()]
	a = input_info[0]
	b = input_info[1]
	check(a, b)


import math

def f(a, b):
	cnt = 0
	while a != 0:
		a //= b
		cnt += 1
	return cnt
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	ans = 32
	if b < 10:
		for i in range(max(2, b), 10):
			cur = i - b + f(a, i)
			ans = min(ans, cur)
	else:
		ans = f(a, b)
	print(ans)


from math import log
t = int(input())
for _ in range(t):
	(n, b) = map(int, input().split())
	mxStep = 0
	extra = 1
	if b == 1:
		b += 1
		extra = 2
	nn = n
	while nn >= b:
		nn //= b
		mxStep += 1
	mnMx = mxStep
	for i in range(1, mxStep):
		nn = n
		bb = b + i
		steps = 0
		while steps < mxStep - i and nn >= bb:
			nn //= bb
			steps += 1
		if steps + i < mnMx:
			mnMx = steps + i
	print(mnMx + extra)


cases = int(input())
while cases:
	cases -= 1
	(a, b) = map(int, input().split())
	ct = 0
	if a == b:
		print(2)
	elif b > a:
		print(1)
	else:
		ct = 0
		mn = 10000000
		i = 0
		stim = 20
		x = a
		y = b
		while stim > 0:
			b += i
			ct += i
			while a > 0:
				if b == 1:
					b = 2
					ct += 1
				a //= b
				ct += 1
			i += 1
			stim -= 1
			a = x
			b = y
			mn = min(mn, ct)
			ct = 0
		print(mn)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
from math import sqrt
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	q = 2000000000.0
	if b != 1:
		w = 0
		e = a
		while e:
			e //= b
			w += 1
		q = min(q, w)
	w = a
	if a < b:
		print(1)
	else:
		for i in range(b + 1, a + 101):
			w = i - b
			e = a
			while e > 0:
				e //= i
				w += 1
			if w <= q:
				q = w
			else:
				break
		print(q)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 10 ** 18
	g = 0
	if b == 1:
		g = 1
		b += 1
	f = 0
	i = b
	ta = a
	while f == 0:
		tcnt = i - b
		while ta != 0:
			ta = ta // i
			tcnt += 1
		if tcnt > ans:
			f = 1
			break
		ans = tcnt
		ta = a
		i = i + 1
	print(ans + g)


import sys
input = sys.stdin.readline
from sys import stdin, stdout
from collections import defaultdict, Counter
M = 10 ** 9 + 7
K = 30

def main():
	for _ in range(int(input())):
		(a, b) = [int(s) for s in input().split()]
		ans = 10 ** 9
		ans1 = 0
		if b == 1:
			b += 1
			ans1 = 1
		for i in range(K):
			c = i
			d = a
			while d:
				d = d // b
				c += 1
			ans = min(ans, c)
			b += 1
		print(ans + ans1)
main()


def verif(a, b):
	c = 0
	if b > a:
		return 1
	while a > 0:
		a = a // b
		c += 1
	return c
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	count = 0
	if b == 1:
		b += 1
		count += 1
	while verif(a, b) > verif(a, b + 1):
		count += 1
		b += 1
	print(verif(a, b) + count)


inn = lambda : int(input())
inm = lambda : map(int, input().split())
ins = lambda : str(input())
ina = lambda : list(map(int, input().split()))

def solve():
	(a, b) = inm()
	if a < b:
		print(1)
		return
	ans = 10 ** 18
	o = b == 1
	for i in range(b + o, b + 11 + o):
		moves = 0
		aa = a
		while aa // i > 1:
			aa //= i
			moves += 1
		if aa > i:
			moves += 1
			aa //= i
		moves += 1 + (aa == i)
		ans = min(ans, moves + i - b)
	print(ans)

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


import sys
input = sys.stdin.readline

def stupid(a, b):
	if a == 0:
		return (0, 1)
	if b > a:
		return (1, 1)
	if b == 1:
		return (stupid(a, b + 1)[0] + 1, 2)
	return min((stupid(a // b, b)[0] + 1, 1), (stupid(a, b + 1)[0] + 1, 2))

def smart(a, b):
	if a == 0:
		return 0
	if b > a:
		return 1
	if b == 1:
		return smart(a, b + 1) + 1
	have = int(1000000000.0)
	for k in range(100):
		x = a
		c = 0
		while x > 0:
			x //= b
			c += 1
		b += 1
		if c + k < have:
			have = c + k
	return have

def solve():
	(a, b) = map(int, input().split())
	print(smart(a, b))
for i in range(int(input())):
	solve()


for i in range(int(input())):
	input_ = input().split()
	(a, b) = (int(input_[0]), int(input_[1]))
	(prev, cur) = (9999999, 0)
	i = 0
	while True:
		cur = i
		y = a
		x = b + i
		while y != 0 and x > 1:
			y = int(y / x)
			cur += 1
		if prev < cur:
			print(prev)
			break
		if x > 1:
			prev = cur
		i += 1


def solve():
	(a, b) = map(int, input().split())
	aa = a
	bb = b
	count = 0
	answer = []
	for j in range(100):
		count = 0
		bb = b
		aa = a
		while bb < 2 + j:
			bb += 1
			count += 1
		while aa > 0:
			aa //= bb
			count += 1
		answer.append(count)
	print(min(answer))
for _ in range(int(input())):
	solve()


def solve(a, b):
	steps = 0
	while a > 0:
		a = a // b
		steps += 1
	return steps
tcs = int(input())
for i in range(tcs):
	(a, b) = [int(x) for x in input().split()]
	i = 0
	if b > a:
		print(1)
		continue
	if b == 1:
		steps = 1
		i += 1
		b += 1
	else:
		steps = 0
	steps = i + solve(a, b)
	for i in range(i + 1, a - b):
		b += 1
		temp = i + solve(a, b)
		if temp > steps:
			break
		steps = temp
	print(steps)


import sys
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	res = sys.maxsize
	for i in range(21):
		if b > 1:
			tmp = i
			k = a
			while k > 0:
				k = k // b
				tmp += 1
			res = min(res, tmp)
		b += 1
	print(res)


import math

def solve():
	(a, b) = [int(x) for x in input().split()]
	if a == b:
		print(2)
		return
	if a < b:
		print(1)
		return
	last = 999999
	for i in range(a):
		if b == 1 and i == 0:
			continue
		this = i
		tmp = a
		while tmp >= 1:
			this += 1
			tmp = tmp / (b + i)
		if this > last:
			break
		last = this
	print(last)
t = int(input())
for i in range(t):
	solve()


for ii in range(int(input())):
	(n, m) = map(int, input().split())
	(x, y, c) = (10 ** 10, 0, 0)
	f = False
	if m == 1:
		f = True
		m += 1
	while 1:
		r = 1
		while n // m ** r > 0:
			r += 1
		if r + y <= x:
			x = r + y
			m += 1
			y += 1
		else:
			break
	if f:
		x += 1
	print(x)


def log(a, b):
	k = 0
	while a > 0:
		k += 1
		a //= b
	return k

def res(a, b):
	if a == 0:
		return 0
	if b > a:
		return 1
	if b == 1:
		return 1 + res(a, b + 1)
	mn = 1000000
	for k in range(30):
		mn = min(mn, k + log(a, b + k))
	return mn

def solve():
	(a, b) = map(int, input().split())
	print(res(a, b))
t = int(input())
for _ in range(t):
	solve()


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def steps(a, b):
	if b == 1:
		return 1000000
	c = 0
	while a != 0:
		a //= b
		c += 1
	return c
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	sb = b
	if b == 1:
		b = 2
	begin_steps = steps(a, b)
	ans = 10 ** 10
	for i in range(begin_steps + 10):
		nb = b + i
		ans = min(ans, steps(a, nb) + nb - sb)
	print(ans)


def add_div(num1, num2):
	minimum = float('inf')
	if num2 > num1:
		return 1
	if num2 > num1 ** 0.5:
		return 2
	for i in range(num2, int(num1 ** 0.5) + 2):
		store = num1
		count = i - num2
		while store != 0:
			if i == 1:
				i = 2
			else:
				store = store // i
			count += 1
		if minimum < count:
			return minimum
		else:
			minimum = count
	return minimum
for test in range(int(input())):
	(a, b) = map(int, input().split())
	print(add_div(a, b))


import math
for rpt in range(int(input())):
	numbers = [int(x) for x in input().split()]
	a = numbers[0]
	b = numbers[1]
	operations = 0
	if b == 1:
		b += 1
		operations += 1
	while True:
		logb = 1
		logb1 = 1
		while b ** logb <= a:
			logb += 1
		while (b + 1) ** logb1 <= a:
			logb1 += 1
		if logb == logb1:
			break
		else:
			b += 1
			operations += 1
	print(operations + int(math.log(a, b)) + 1)


import math
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	(d, ans) = (0, 10 ** 9)
	if b == 1:
		(b, d) = (2, 1)
	for i in range(b, b + 10):
		(c, e) = (i - b, a)
		while e > 0:
			c += 1
			e = e // i
		ans = min(ans, c)
	print(ans + d)


def main():
	tests = int(input())
	while tests > 0:
		(a, b) = [int(x) for x in input().split(' ')]
		result = 50
		start = 1 if b == 1 else 0
		for i in range(start, result):
			b_aux = b + i
			a_aux = a
			movements = i
			while a_aux > 0:
				a_aux = int(a_aux / b_aux)
				movements += 1
				if movements > result:
					break
			if movements < result:
				result = movements
		print(result)
		tests -= 1
main()


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
from math import log
sa = lambda : input()
sb = lambda : int(input())
sc = lambda : input().split()
sd = lambda : list(map(int, input().split()))
se = lambda : float(input())
sf = lambda : list(input())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7

def hnbhai():
	(a, b) = sd()
	count_ = 0
	if b == 1:
		b += 1
		count_ += 1
	max_ = float('inf')
	for i in range(32):
		x = b + i
		y = a
		t = count_ + i
		while y > 0:
			t += 1
			y = y // x
		max_ = min(max_, t)
	print(max_)
for _ in range(sb()):
	hnbhai()


import math
T = int(input())
for t in range(T):
	(a, b) = [int(k) for k in input().split()]
	ans = float('inf')
	if b == 1:
		init_cnt = 1
		b += 1
	else:
		init_cnt = 0
	for i in range(20):
		tmp = a
		cnt = init_cnt
		while tmp > 0:
			cnt += 1
			tmp //= b + i
		ans = min(ans, cnt + i)
	print(ans)


import sys
import math
from collections import Counter, defaultdict
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()

def case():
	(a, b) = MAP()
	t = b
	ans = 0
	if b == 1:
		ans += 1
		b += 1
	temp = a
	while temp > 0:
		temp = temp // b
		ans += 1
	for i in range(b + 1, ans + b):
		temp = a
		x = i - t
		while temp > 0:
			temp = temp // i
			x += 1
		ans = min(ans, x)
	print(ans)
for _ in range(IN()):
	case()


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	l = a
	g = []
	if b == 1:
		c = c + 1
		b = b + 1
	for j in range(int(math.sqrt(l)) + 1):
		k = c
		a = l
		while a > 0:
			a = a // (b + j)
			k = k + 1
		g.append(k + j)
		if k < b + j - 1:
			break
	print(min(g))


import math

def mylog(a, b):
	n = 0
	while a != 0:
		a = a // b
		n += 1
	return n
for t in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	if b == 0:
		b += 1
		c += 1
	if b == 1:
		b += 1
		c += 1
	while mylog(a, b) >= mylog(a, b + 1) + 1:
		b += 1
		c += 1
	print(mylog(a, b) + c)


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

def mi():
	return map(int, input().split())
for _ in range(ii()):
	(a, b) = mi()
	ans = 1000000000000
	for i in range(0, 30):
		temp = i
		c = b + i
		if c == 1:
			continue
		d = a
		while d != 0:
			d //= c
			temp += 1
		ans = min(ans, temp)
	print(ans)


import collections
import math
from heapq import *
for t in range(int(input())):
	(a, b) = map(int, input().split())
	pre = 0
	if a == b:
		print(2)
		continue
	if a < b:
		print(1)
		continue
	while b < 2:
		b += 1
		pre += 1
	out = float('inf')
	while True:
		val = a
		ans = 0
		while val > 0:
			ans += 1
			val //= b
		if ans + pre > out:
			break
		out = pre + ans
		b += 1
		pre += 1
	print(out)


import math
import sys

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

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

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

def solve():
	(a, b) = getmany()
	if a <= b:
		print(1 + a // b)
		return
	if b > 32:
		s = 0
		while a != 0:
			a //= b
			s += 1
		print(s)
		return
	if b == 1:
		mins = sys.maxsize
		for i in range(b + 1, 33):
			x = a
			s = i - b
			while x != 0:
				x //= i
				s += 1
			mins = min(mins, s)
		print(mins)
		return
	if b <= 32:
		mins = sys.maxsize
		for i in range(b, 33):
			x = a
			s = i - b
			while x != 0:
				x //= i
				s += 1
			mins = min(mins, s)
		print(mins)
		return
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline

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

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

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

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

class Solution:

	def solve(self, a, b):
		count = 0
		if b == 1:
			b += 1
			count += 1
		ans = []
		for i in range(10):
			a_1 = a
			b_1 = b
			count1 = 0
			count1 = max(count1, count)
			for j in range(i):
				b_1 += 1
				count1 += 1
			while a_1 != 0:
				a_1 = math.floor(a_1 / b_1)
				count1 += 1
			ans.append(count1)
		return min(ans)
t = inp()
A = Solution()
for i in range(t):
	(a, b) = invr()
	ans = A.solve(a, b)
	print(ans)


import sys
input = sys.stdin.buffer.readline
for t in range(int(input())):
	(A, B) = map(int, input().split())
	X = 0
	(C, D) = (A, B)
	if B == 1:
		X = 1
		D = 2
	while C > 0:
		C //= D
		X += 1
	ANS = X
	for i in range(1, X):
		(C, D) = (A, B + i)
		while C > 0:
			C //= D
			i += 1
		ANS = min(ANS, i)
	print(ANS)


import math
for _ in range(int(input())):
	ans = 1000000000
	(a, b) = map(int, input().split())
	for i in range(0, 32):
		b1 = b + i
		t = i
		a1 = a
		if b1 == 1:
			continue
		while a1 > 0:
			a1 = a1 // b1
			t += 1
		ans = min(ans, t)
	print(ans)


import operator
import sys
inf = sys.stdin
input = inf.readline

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

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

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

def check_seq(a, b):
	if b > a:
		return 1
	if b == a:
		return 2
	res = 10000
	for i in range(40):
		if b == 1 and i == 0:
			continue
		cur_a = a
		cur_b = b + i
		cur_res = i
		while cur_a // cur_b:
			cur_a = cur_a // cur_b
			cur_res += 1
		cur_res += 1
		res = min(res, cur_res)
	return res

def main():
	samples = read_one_int()
	for _ in range(samples):
		(a, b) = read_list_of_ints()
		cur_res = check_seq(a, b)
		print(cur_res)
main()


from sys import stdin
import math

def main():
	cases = int(stdin.readline().strip())
	while cases:
		(a, b) = map(int, stdin.readline().split())
		if a == b:
			print(2)
		elif a < b:
			print(1)
		else:
			i = b
			res = float('inf')
			aux = a
			min_ = 0
			r = 0
			if b == 1:
				r += 1
				i += 1
				b += 1
			while i <= b + 29:
				aux = a
				min_ = 0
				while aux >= 1:
					aux //= i
					min_ += 1
				min_ += i - b + r
				if min_ < res:
					res = min_
				i += 1
			print(res)
		cases -= 1
main()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	t = 100
	for d in range(33):
		if b + d > 1:
			c = d
			(x, y) = (a, b + d)
			while x:
				x //= y
				c += 1
			t = min(t, c)
	print(t)


for p in range(int(input())):
	(a, b) = map(int, input().split())
	(d, c) = (40, 0)
	for j in range(30):
		a1 = a
		if b == 1:
			b = b + 1
			c = c + 1
		f = 0
		while a1 != 0:
			a1 //= b
			f += 1
		d = min(d, f + c)
		b = b + 1
		c = c + 1
	print(d)


def div(a, b):
	count = 0
	while a > 0:
		a = int(a / b)
		count += 1
	return count
T = int(input())
for i in range(T):
	nums = list(map(int, input().split()))
	a = nums[0]
	b = nums[1]
	counter = 0
	if b == 1:
		b += 1
		counter += 1
	while 1:
		if div(a, b) >= div(a, b + 1) + 1:
			b += 1
			counter += 1
		else:
			break
	counter = counter + div(a, b)
	print(counter)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	i = 0 if b >= 2 else 2 - b
	res = a + 3
	while i < res:
		cont = i
		x = a
		d = b + i
		while x:
			x //= d
			cont += 1
		if cont < res:
			res = cont
		i += 1
	print(res)


import sys
t = int(input())
res = []

def check(a, b):
	c = 0
	if b == 1:
		b += 1
		c += 1
	while a != 0:
		a //= b
		c += 1
	return c
for i in range(t):
	(a, b) = map(int, input().split())
	c = 0
	m = sys.maxsize
	for i in range(0, 7):
		c = check(a, b + i) + i
		if c < m:
			m = c
	res.append(m)
for i in res:
	print(i)


num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	n = b
	r = 99
	while n - b < r:
		m = a
		i = 0
		if n > 1:
			while m:
				i += 1
				m //= n
			r = min(r, n - b + i)
		n += 1
	print(r)


t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	if a < b:
		tt = 1
		print('%d' % tt)
	elif a == b:
		tt = 2
		print('%d' % tt)
	else:
		tt = 0
		ans = 1061109567
		for i in range(b, b + 1000):
			if i == 1:
				continue
			s = a
			tt = 0
			while s > 0:
				s = s // i
				tt += 1
			ans = min(ans, tt + i - b)
		print('%d' % ans)


def f(a, b):
	k = 0
	while a > 0:
		a = a // b
		k += 1
	return k
(T,) = map(int, input().split())
for _ in range(T):
	(a, b) = map(int, input().split())
	g = 0
	if a == 1 and b == 1:
		print(2)
		continue
	if b == 1:
		b += 1
		g = 1
	R = 10 ** 18
	for j in range(min(1000, a + 2)):
		r = g + j + f(a, b)
		b += 1
		R = min(R, r)
	print(R)


def func(a, b, ops, x):
	if b > a:
		ops += 1
		global fim
		fim = ops
		return
	if a == b or b <= x:
		ops += 1
		b += 1
		func(a, b, ops, x)
		return
	a = a // b
	ops += 1
	func(a, b, ops, x)
	return
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ops = 0
	acu = 1
	vals = []
	while True:
		func(a, b, ops, acu)
		vals.append(fim)
		if len(vals) > 10 or min(vals) == 1:
			print(min(vals))
			break
		acu += 1


for t in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	lst = []
	bcount = 0
	acopy = a
	bplus = b + 10
	if a < b:
		print(1)
	elif a == b:
		print(2)
	else:
		while True:
			if b == bplus:
				break
			else:
				count = 0
				if b == 1:
					b += 1
					bcount += 1
				a = acopy
				while True:
					if int(a) == 0:
						break
					else:
						a = a / b
						count += 1
				b += 1
				lst.append(count + bcount)
				bcount += 1
		print(min(lst))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

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

def li():
	return list(mi())

def lsi():
	return list(msi())

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

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

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

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

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, factorial, cos, tan, sin, radians, floor, log2
import bisect
import random
import string
from decimal import *
getcontext().prec = 50
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def gcd1(a):
	if len(a) == 1:
		return a[0]
	ans = a[0]
	for i in range(1, len(a)):
		ans = gcd(ans, a[i])
	return ans

def mykey(x):
	return (x[0], -x[1])

def fun(a, x):
	l = 0
	h = len(a)
	while l < h:
		mid = (l + h) // 2
		if x[0] >= a[mid][0]:
			l = mid + 1
		else:
			h = mid
	return l

def main():
	for _ in range(ii()):
		(a, b) = mi()
		ans = 1000000000.0
		for i in range(b, b + 100):
			d = a
			c = 0
			if i == 1:
				ans = min(ans, a - b + 2)
				continue
			while d >= i:
				d //= i
				c += 1
			ans = min(ans, c + 1 + (i - b))
		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')

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


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	ans = float('inf')
	if b == 1:
		b += 1
		c += 1
	for i in range(101):
		s = 0
		k = a
		while k:
			s += 1
			k //= b + i
		ans = min(ans, s + c + i)
	print(ans)


import os
import sys
from io import BytesIO, IOBase

def func(a, b):
	if b == 1:
		return 100000000
	cnt = 0
	while a > 0:
		a = a // b
		cnt += 1
	return cnt

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		ans = float('INF')
		for i in range(82):
			ans = min(ans, func(a, b + i) + i)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


t = int(input())
for i in range(t):
	(aa, bb) = [int(i) for i in input().split()]
	minc = 0
	b = bb
	a = aa
	while a > 0:
		if a == b:
			b = b + 1
			minc = minc + 1
		elif b == 1:
			b = b + 1
			minc = minc + 1
		minc = minc + 1
		a = int(a / b)
	a = aa
	b = bb
	maxc = minc
	ans = minc
	c = 1
	while c <= maxc:
		b = bb + c
		minc = c
		a = aa
		while a > 0:
			if a == b:
				b = b + 1
				minc = minc + 1
			elif b == 1:
				b = b + 1
				minc = minc + 1
			minc = minc + 1
			a = int(a / b)
		if minc < ans:
			ans = minc
		c = c + 1
	print(ans)


import math
import sys
t = int(input())
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	ans = 100000000000000
	k = 0
	(a1, b1) = (a, b)
	if b1 == 1:
		b1 += 1
		k = 1
	while a1 > 0:
		a1 = a1 // b1
		k += 1
	ans = k
	for b1 in range(b, max(math.ceil(math.sqrt(a)) + 2, 3)):
		if b1 == 1:
			continue
		k = b1 - b
		a1 = a
		while a1 > 0:
			a1 = a1 // b1
			k += 1
		if k < ans:
			ans = k
	print(ans)


import math
trails = int(input())
answer_list = []
for x in range(trails):
	numbers = input()
	numbers = numbers.split()
	a = int(numbers[0])
	b = int(numbers[1])
	answer = 0
	if b == 1:
		answer += 1
		b += 1
	while True:
		y = int(math.log(a, b))
		if (b + 1) ** (y - 1) > b ** y:
			answer += 1
			b += 1
		else:
			break
	result = a
	while result != 0:
		result = result // b
		answer += 1
	answer_list.append(answer)
for s in answer_list:
	print(s)


def do(cnt, a, b):
	while a >= 1:
		cnt += 1
		a = a // b
	return cnt
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	cnt = 0
	if b == 1:
		b += 1
		cnt += 1
	print(min([do(cnt + i, a, b + i) for i in range(10)]))


for _ in range(int(input())):
	cnt = 0
	(a, b) = map(int, input().split())
	s = []
	for i in range(0, 30):
		cnt = 0
		if b == 1 and i == 0:
			continue
		cnt = cnt + i
		k = a
		while k:
			k //= b + i
			cnt += 1
		s.append(cnt)
	print(min(s))


import math
t = int(input())
counts = []
for _ in range(t):
	(x, y) = map(int, input().split())
	count = 0
	while y <= 1:
		y += 1
		count += 1
	prev = math.log(x, y)
	i = 1
	while prev - math.log(x, y + i) >= 1:
		prev = math.log(x, y + i)
		i += 1
	y = y + i - 1
	count += i - 1
	while x > 0:
		if y == x:
			y += 1
			count += 1
		else:
			x = x // y
			count += 1
	counts.append(count)
for i in counts:
	print(i)


MAX_OPS = 30
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if b > a:
		print(1)
		continue
	min_ops = a - b + 2
	for i in range(0 if b > 1 else 1, MAX_OPS + 1):
		current_b = b + i
		current_ops = i
		current_a = a
		while current_a > 0:
			current_a = current_a // current_b
			current_ops += 1
		min_ops = min(min_ops, current_ops)
	print(min_ops)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	a += 1
	ans = a
	if a <= b:
		ans = 1
	for n in range(2, 31):
		root = int(a ** (1 / n)) + 1
		if (root - 1) ** n >= a:
			root -= 1
		elif root ** n < a:
			root += 1
		if b < root:
			nans = root - b + n
		else:
			nans = n
		if ans > nans:
			ans = nans
	print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ans1 = 0
	ans2 = 0
	ans3 = 0
	while True:
		x = 0
		y = 0
		ans1 = ans3
		ans2 = ans3
		if b == 1:
			b = 2
			ans1 += 1
			ans2 += 1
			ans3 += 1
		else:
			b = b
		while True:
			if b ** x > a:
				b += 1
				ans2 += 1
				ans3 += 1
				break
			else:
				x += 1
				ans1 += 1
		while True:
			if b ** y > a:
				break
			else:
				y += 1
				ans2 += 1
		if ans1 < ans2:
			ans = ans1
			break
		else:
			continue
	print(ans)


from math import log, ceil, floor
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	op = 0
	l = []
	m = 9999999
	while n != 0:
		if k == 1:
			k += 1
			op += 1
		else:
			temp = n
			c = 0
			while n != 0:
				n //= k
				c += 1
			n = temp
			if m < op + c:
				break
			m = min(m, op + c)
			k += 1
			op += 1
	print(m)


def v(a, b, c=0):
	return c if a == 0 else v(a // b, b, c + 1)
for _ in range(int(input())):
	k = 0
	(a, b) = map(int, input().split())
	if b == 1:
		k += 1
		b += 1
	c = 1000000000
	while 1 == 1:
		_ = k + v(a, b)
		if _ <= c:
			c = _
		else:
			break
		b += 1
		k += 1
	print(c)


from math import *
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 10 ** 9 + 10
	c = 0
	if b < 2:
		b += 1
		c += 1
	for i in range(0, ceil(sqrt(a))):
		cc = 0
		cc += i
		curr = a
		bb_ = b + i
		while curr:
			curr //= bb_
			cc += 1
		ans = min(ans, cc)
	print(ans + c)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	smallest = 50000
	for i in range(20):
		erste_zahl = a
		zweite_zahl = b + i
		actions = i
		if zweite_zahl <= 1:
			zweite_zahl += 1
			actions += 1
		while erste_zahl > 0:
			erste_zahl = erste_zahl // zweite_zahl
			actions += 1
		if actions < smallest:
			smallest = actions
	print(smallest)


def solv(a, b):
	c = 0
	if b == 1:
		b += 1
		c += 1
	while a:
		a = a // b
		c += 1
	return c
for test in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	ans = []
	for i in range(31):
		ans.append(solv(a, b + i) + i)
	print(min(ans))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = []
	for i in range(7):
		y = a
		c = 0
		if b == 1 and i == 0:
			pass
		else:
			while y != 0:
				y //= b + i
				c += 1
			l.append((c + i, b + i))
	print(min(l)[0])


import math
case = int(input())
for i in range(case):
	(a, b) = map(int, input().split())
	flag = False
	ll = [-1]
	s = b
	while b < 10 ** 10 and (not flag):
		count = 0
		c = a
		if b == 1:
			b = 2
		while not flag:
			c //= b
			count += 1
			if c == 0:
				break
		ll.insert(-1, count + b - s)
		b += 1
		for t in range(len(ll) - 1):
			if ll[t] < ll[t + 1]:
				flag = True
				break
	ll.pop(-1)
	print(min(ll))


from math import *
from collections import deque
from copy import deepcopy
import sys

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

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

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

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

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

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

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

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

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(inp())
for _ in range(t):
	(a, b) = multi()
	if b > a:
		print(1)
		continue
	ans = 0
	if b == 1:
		b += 1
		ans += 1
	while a > 0:
		if log(a, b) - log(a, b + 1) > 1:
			b += 1
		else:
			a = floor(a / b)
		ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	if m == 1:
		c += 1
		m += 1
	l = 0
	ans = 10 ** 9
	while 1:
		e = 0
		t = n
		while t > 0:
			t = t // m
			e += 1
		if ans < e + l:
			break
		else:
			ans = e + l
		m += 1
		l += 1
	print(ans + c)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	count = float('inf')
	for i in range(max(b, 2), b + 101):
		steps = 0
		steps += i - b
		s = a
		while s > 0:
			s //= i
			steps += 1
		count = min(count, steps)
	print(count)


import math

def solution(a, b):
	step_min = math.inf
	if a < b:
		return 1
	for i in range(0, int(math.log(a + 1) / math.log(b + 1))):
		a_bis = a
		b_bis = b
		step = 0
		if b_bis == 1:
			b_bis += 1
			step += 1
		b_bis += i
		step += i
		while a_bis != 0:
			a_bis = a_bis // b_bis
			step += 1
		step_min = min(step, step_min)
	return step_min
for i in range(int(input())):
	(a, b) = map(int, input().split(' '))
	print(solution(a, b))


T = int(input())

def cnt(a, b):
	cnt = 0
	while a > 0:
		a = a // b
		cnt += 1
	return cnt

def solve():
	(a, b) = map(int, input().split(' '))
	M = cnt(a, b) if b > 1 else 1 + cnt(a, b + 1)
	for i in range(1, 10 ** 7):
		c = i + cnt(a, b + i)
		if c <= M:
			M = c
			continue
		else:
			break
	return M
for _ in range(T):
	print(solve())


import math
n = int(input())
for x in range(n):
	(a, b) = map(int, input().split())
	res = 0
	if b == 0:
		res += 1
		b += 1
	if b == 1:
		res += 1
		b += 1
	while math.log(a, b) - math.log(a, b + 1) > 1:
		b += 1
		res += 1
	while a > 0:
		a //= b
		res += 1
	print(res)


from math import ceil
from math import log
from sys import maxsize
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = maxsize
	if k >= 30:
		ans = 0
		while n:
			ans += 1
			n //= k
		print(ans)
	else:
		for i in range(2, 31):
			tmp = abs(k - i)
			z = n
			while z:
				tmp += 1
				z //= i
			ans = min(ans, tmp)
		print(ans)


from math import log
t = int(input())
for i in range(t):
	total = 0
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if b == 1:
		b += 1
		total += 1
	b0 = b
	loga = log(a)
	while True:
		if loga // log(b) == loga // log(b + 1):
			max = b
			break
		else:
			b += 1
	total += max - b0
	while a != 0:
		a //= b
		total += 1
	print(total)


def incre(a, b):
	flag = 0
	if a // b == 0:
		return 1
	if b == 1:
		b += 1
		flag = 1
	tb = b
	ans = float('inf')
	if a // b == 0:
		return 1 + flag
	while b <= a:
		ta = a
		cnt = b - tb
		while ta:
			ta //= b
			cnt += 1
		b += 1
		if ans < cnt:
			return ans + flag
		ans = min(ans, cnt)
	return ans + flag
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	print(incre(a, b))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	op = 10 ** 9
	for k in range(b, b + 15):
		c = a
		t = 0
		if k == 1:
			continue
		while c:
			c = c // k
			t += 1
		op = min(op, t + k - b)
	print(op)


from collections import Counter, deque, defaultdict
from itertools import accumulate, product, groupby
import operator
import math
from functools import reduce

def solve():
	(a, b) = [int(char) for char in input().split()]

	def divideCount(nb):
		if nb == 1:
			return 10 ** 9
		na = a
		count = 0
		while na != 0:
			na //= nb
			count += 1
		return count
	ans = 10 ** 9
	for inc in range(31):
		possible_b = b + inc
		ans = min(ans, inc + divideCount(possible_b))
	return ans
for _ in range(int(input())):
	print(solve())


n = int(input())
a = 0
b = 0
for i in range(n):
	(a, b) = map(int, input().split())
	ans = float('inf')
	for c in range(30):
		if b + c == 1:
			continue
		res = c
		x = a
		while x > 0:
			x = x // (b + c)
			res += 1
		ans = min(ans, res)
	print(ans)


import math

def get_num_div(a, b):
	result = 0
	while a > 0:
		a //= b
		result += 1
	return result
T = int(input())
for t in range(T):
	(a, b) = tuple([int(x) for x in input().split()])
	num_operation = 0
	if b == 1:
		b += 1
		num_operation += 1
	min_new_op = a + 1
	for num_plus in range(1000000):
		new_b = b + num_plus
		num_op_left = get_num_div(a, new_b)
		cur_new_op = num_plus + num_op_left
		if cur_new_op <= min_new_op:
			min_new_op = cur_new_op
		else:
			break
	num_operation += min_new_op
	print(num_operation)


import math

def alpha(x, b):
	ct = 0
	while x != 0:
		x = x // b
		ct += 1
	return ct

def solve(x, b):
	k = 0
	if b == 1:
		b = 2
		k = 1
	z = [alpha(x, b + i) + i for i in range(16)]
	return min(z) + k
t = int(input())
for _ in range(t):
	(x, b) = [int(i) for i in input().split()]
	print(solve(x, b))


import math
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	count = 0
	if b == 1:
		b += 1
		count += 1
	while a != 0:
		p = int(math.log2(a) / math.log2(b))
		q = int(math.log2(a) / math.log2(b + 1))
		if q + 1 <= p:
			b = b + 1
		else:
			a = a // b
		count += 1
	print(count)
	t -= 1


def getCount(a, b, ans):
	while a != 0:
		if a == b or b == 1:
			b += 1
		else:
			a = a // b
		ans += 1
	return ans
t = int(input())
for _ in range(t):
	(a, b) = [int(s) for s in input().split(' ')]
	if a < b:
		print(1)
	else:
		a1 = getCount(a, b, 0)
		a2 = 0
		c = 0
		while True:
			c += 1
			b += 1
			a2 = getCount(a, b, c)
			if a2 > a1:
				break
			else:
				a1 = a2
		print(a1)


def find(a, b):
	moves = 0
	while a > 0:
		a = a // b
		moves += 1
	return moves

def solve(a, b, ans):
	min_moves = float('inf')
	if b == 1:
		start = 1
	else:
		start = 0
	for add in range(start, pow(10, 3)):
		moves = add + find(a, b + add)
		min_moves = min(min_moves, moves)
	ans.append(str(min_moves))

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