#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() int main() { cin.tie(nullptr); int T; cin >> T; rep(test, 0, T) { ll N, M; cin >> N >> M; ll k = (N + 3) / 4; ll left = 8 * k - N; if (left >= M) cout << k << '\n'; else { ll d = M - left; cout << k + (d + 7) / 8 << '\n'; } } }