/* -*- coding: utf-8 -*- * * 2921.cc: No.2921 Seated in Classroom - yukicoder */ #include #include using namespace std; /* constant */ /* typedef */ using ll = long long; /* global variables */ /* subroutines */ /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int n, m; scanf("%d%d", &n, &m); int x0 = 0, x1 = n + m; while (x0 + 1 < x1) { int x = ((ll)x0 + x1) / 2; if ((ll)x * 4 >= n && (ll)x * 8 >= n + m) x1 = x; else x0 = x; } printf("%d\n", x1); } return 0; }