#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ ll n, m; cin >> n >> m; cout << max((n - 1) / 4, (n + m - 1) / 8) + 1 << '\n'; } }