typedef long long ll; typedef long double ld; #include using namespace std; signed main() { ll t; std::cin >> t; for (int iiii = 0; iiii < t; iiii++) { ll n,m; std::cin >> n>>m; ll atl = (n+3)/4; m -= atl*8-n; std::cout << atl+(max(0ll, m)+7)/8 << std::endl; } };