#![allow(non_snake_case, unused_must_use, unused_imports)] use std::io::{self, prelude::*}; fn main() { let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout()); let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock())); for _ in 0..stdin.next().unwrap().parse::().unwrap() { solve(&mut stdin, &mut buffer); } } fn solve(stdin: &mut std::str::SplitWhitespace, buffer: &mut io::BufWriter) { macro_rules! input { ($t: ty) => { stdin.next().unwrap().parse::<$t>().unwrap() }; ($t: ty, $n: expr) => { (0..$n).map(|_| input!($t)).collect::>() }; } let mut N = input!(isize); let mut M = input!(isize); let mut ans = 0; let p = N / 4; N -= 4 * p; if M >= 4 * p { M -= 4 * p; } else { M = 0; } ans += p; if N > 0 { ans += 1; M -= 8 - N; if M < 0 { M = 0; } N = 0; } ans += (M + 7) / 8; writeln!(buffer, "{}", ans); }