#include #include using namespace std; using ll = long long; void solve(){ ll n, m; cin >> n >> m; ll need = (n + 3) / 4; m -= need * 4; if (m <= 0){ cout << need << endl; return; } m -= need * 4 - n; need += (m + 7) / 8; cout << need << endl; return; } int main(){ int t; cin >> t; while(t--) solve(); }