#include <stdio.h>
#include <string>
#include <vector>
#include <array>
#include <memory>
#include <iostream>
#include <algorithm>

using namespace std;
long long int memo[100][100];
int main(void) {
	//boost::shared_ptr<vector<string>>  log(boost::make_shared<vector<string>>());
	//log->push_back("dd");
	//log->push_back("dde");
	//boost::shared_ptr<vector<string>>  blog(boost::make_shared<vector<string>>());
	//blog->push_back("fsdfsdfd");
	//OpChara a(3,log);
	//OpChara b(2,log);
	//OpChara c(1, log);
	//log->push_back("dde3");
	//std::ofstream ofs("output1.txt");
	//assert(ofs);
	//boost::archive::text_oarchive oa(ofs);
	//oa << (a);
	//ofs.close();
	//std::ofstream cofs("output2.txt");
	//assert(cofs);
	//boost::archive::text_oarchive coa(cofs);
	//coa << (b);
	//cofs.close();

	//// de-serialize
	//std::ifstream ifs("output1.txt");
	//assert(ifs);
	//boost::archive::text_iarchive ia(ifs);

	//ia >> (b);
	//
	//ifs.close();
	//std::ifstream cifs("output2.txt");
	//assert(cifs);
	//boost::archive::text_iarchive iac(cifs);
	//iac >> c;
	//
	//// check
	//b.actionlog->push_back("111");

	/*int n, m;
	cin >> n >> m;
	vector<vector<tyu>> Pots;
	for (int i = 0; i < n; ++i) {
		Pots.push_back(vector<tyu>());
		int k;
		cin >> k;
		for (int j = 0; j < k; ++j) {
			int s,h;
			cin >> s >> h;
			Pots[i].push_back({ s,h });
		}
	}
	double ans=0;
	while (1) {

	
		vector<memo> amemo;
		for (int i = 0; i < n; ++i) {
			double h = 0;
			int taiseki = 0;
			for (int j = 0; j < Pots[i].size(); ++j) {
				bool flag = false;
				if (m > taiseki+ Pots[i][j].height*Pots[i][j].wide) {
					h += Pots[i][j].height;
					taiseki += Pots[i][j].height*Pots[i][j].wide;
				}
				else {
					flag = true;
					h += (double(m - taiseki)) / Pots[i][j].wide;
					taiseki = m;
				}
				const double akouritu = double(taiseki) / h;
				amemo.push_back({ akouritu, i, h,j,taiseki });
				if (flag) { break; }
			}
		}
		sort(amemo.begin(), amemo.end(), [](const memo m1, const memo m2) {return m1.kouritu < m2.kouritu; });
		bool flag=false;
		memo me = *amemo.begin();
		m -= me.taiseki;
		if (m < 0.0000000001) {
			flag = true;
		}
		ans += me.height;
		for (int i = 0; i < me.num + 1;++i) {
			Pots[me.id].erase(Pots[me.id].begin());
		}
		if (flag) {
			break;
		}
		
	}
	printf("%.10d", &ans);
	cout << ans;*/


	
	for (int i = 0; i < 100; ++i) {
		for (int j = 0; j < 100; ++j) {
			memo[i][j] = 999999999999999999;
		}
	}
	for (int i = 0; i < 100; ++i) {
		memo[1][i] = i;//x+1こ卵があるとき　e<=iならy回で割れる
		memo[i][2] = 2;//x+1こ卵があるとき　e<=iならy回で割れる
		memo[i][1] = 1;//x+1こ卵があるとき　e<=iならy回で割れる
		memo[i][0] = 0;//x+1こ卵があるとき　e<=iならy回で割れる
		memo[0][i] = 999999999999999999;//x+1こ卵があるとき　e<=iならy回で割れる
	}
	
	for (int i = 2; i < 50; ++i) {
		for (int j = 2; j < 50; ++j) {
			for (int k = 0; k < j-2; ++k) {
				memo[i][j] = min(memo[i][j], 1+max(memo[i][k], memo[i - 1][j-1-k]));
			}
		}
	}
	for (int i = 0; i < 100; ++i) {
		for (int j = 0; j < 100; ++j) {
			memo[i][j] = 999999999999999999;
		}
	}
	for (int i = 0; i < 100; ++i) {
		memo[1][i] = i;//x+1こ卵があるとき　e<=iならy回で割れる
		memo[i][1] = 1;//x+1こ卵があるとき　e<=iならy回で割れる
	}

	for (int i = 2; i <= 50; ++i) {
		for (int j = 2; j <= 50; ++j) {
				memo[i][j] = 1 + memo[i][j - 1] + memo[i - 1][j - 1];
			
		}
	}
	int tl;
	cin >> tl;
	for (int i = 0; i < tl; ++i) {
		long long int n;
		long long int e;
		cin >> n >> e;
		for (int j = 1; j < 51; ++j) {
			if (memo[e][j] >= n) {
				cout << j << endl;
				break;
			}
		}
	}
	
	return 0;

}

Measured memory_bytes: 1244