#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; cin>>t; while(t--){ ll n,m; cin>>n>>m; ll ng=0,ok=1e18; while(ok-ng>1){ ll mid=(ok+ng)/2; if(4*mid>=n && 8*mid>=n+m) ok=mid; else ng=mid; } cout<