#include #include using namespace atcoder; // using mint = modint998244353; using namespace std; using ll = long long; const int INF = 1001001001; const ll LINF = 3001001001001001001; const int MOD = 998244353; const string Yes = "Yes"; const string No = "No"; #define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i) #define rep(i, n) reps(i, 0, n) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} template istream &operator>>(istream &is, vector &v) {for (T &in : v)is >> in;return is;} // #include // template // using ordered_set = __gnu_pbds::tree, rb_tree_tag, tree_order_statistics_node_update>; int main() { int T;cin>>T; while(T--) { ll n,m;cin>>n>>m; ll x = (n+3)/4; m -= (4-n%4)%4; m -= 4*x; if(m>0) x += (m+8)/8; cout << x << endl; } return 0; }