#include // #include using namespace std; // using namespace atcoder; #define rep(i, a, n) for(int i = a; i < n; i++) #define rrep(i, a, n) for(int i = a; i >= n; i--) #define inr(l, x, r) (l <= x && x < r) #define ll long long #define ld long double // using mint = modint1000000007; // using mint = modint998244353; constexpr int IINF = 1001001001; constexpr ll INF = 1e18; template void chmax(t&a,u b){if(a void chmin(t&a,u b){if(b> t; while(t--){ ll n, m; cin >> n >> m; ll ans = (n+3)/4; m -= ((n+3)/4)*4+(4-n%4)%4; if(m > 0) ans += (m+7)/8; cout << ans << endl; } return 0; }