#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; assert(1 <= T && T <= 100000); while (T--) { ll N, M; cin >> N >> M; assert(0 <= N && N <= 1000000000LL); assert(0 <= M && M <= 1000000000LL); if (N % 2 == 1) N--; if (M % 2 == 1) M--; if (N < 2 * M) { cout << (3 * (N / 4)) << endl; } else { ll ans = 3 * (M / 2); N -= 2 * M; M = 0; ans += 6 * (N / 10); N %= 10; if (6 <= N) ans += 3; cout << ans << endl; } } }