#![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 N = input!(usize); let X = input!(u64); let C = input!(u64, N); let mut ans = u64::MAX; // 左側 let mut left = X; let mut isok = true; for &c in C.iter() { if X < (1 << c) { isok = false; break; } if (X >> c) & 1 != 1 { let k = X.next_power_of_two() >> 1; left = std::cmp::min(left, k - 1); } } if isok { ans = std::cmp::min(ans, (X - left) * 2); } // 右側 let mut right = X; for c in C { if (X >> c) & 1 != 1 { let k = ((X >> c) << c) + (1 << c); right = std::cmp::max(right, k); } } ans = std::cmp::min(ans, (right - X) * 2); writeln!(buffer, "{}", ans); }