#include using namespace std; #define rep(i,n) for(int i=0;i dx = {0,1,0,-1} , dy = {1,0,-1,0}; //chmin , chmax template bool chmin(T &a , T b){ if(a > b){a = b ; return 1;} return 0; } template bool chmax(T &a , T b){ if(a < b){a = b ; return 1;} return 0; } //io template std::istream& operator>>(std::istream& is , pair &p){ is >> p.first >> p.second; return is; } template std::ostream& operator<<(std::ostream& os , const pair &p){ os << " [" << p.first << " : " << p.second << "] "; return os; } //vio template void printv(vector &v){ rep(i,(int)v.size()){ cout< void printvv(vector> &vv){rep(i,(int)vv.size()) printv(vv[i]);} template void printve(vector &v){ rep(i,(int)v.size()){ cerr< void printvve(vector> &vv){rep(i,(int)vv.size()) printve(vv[i]);} template void vin(vector &v){for(auto &vi : v) cin>>vi;} template void vvin(vector> &vv){for(auto &vvi : vv) vin(vvi);} int main(){cin.tie(0);ios::sync_with_stdio(0); int t; cin >> t; for(int i=0;i> n >> m; //min((n - 2 * k) // 4 , (m + 4 * k) // 2) //(n - 2 * m) / 10 = k; ll K = (n - 2 * m) / 10ll; ll kmax = n / 2ll; ll ans = max(min(n / 4ll , m / 2ll) , min((n - 2 * kmax) / 4ll , (m + 4 * kmax) / 2ll)); for(ll k = -100 + K ; k <= 100 + K ; k++){ if(k < 0) continue; if(n - 2ll * k < 0) continue; chmax(ans , min((n - 2ll * k) / 4ll , (m + 4ll * k) / 2ll)); } cout << 3ll * ans << endl; } }