import std; void main () { int T = readln.chomp.to!int; auto ans = new int[](T); foreach (i; 0..T) { int N, M; readln.read(N, M); bool f (int x) { // 充電席 if (4L * x < N) return false; long rem_ch = 4L * x - N; return M <= rem_ch + 4L * x; } int ok = 10 ^^ 9, ng = 0; while (1 < abs(ok - ng)) { int mid = (ok + ng) / 2; if (f(mid)) { ok = mid; } else { ng = mid; } } ans[i] = ok; } foreach (a; ans) writeln(a); } void read (T...) (string S, ref T args) { import std.conv : to; import std.array : split; auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }