use std::{convert::identity, io::stdin}; pub trait Boolinator: Sized { fn as_some_from(self, some: F) -> Option where F: FnOnce() -> T; } impl Boolinator for bool { fn as_some_from(self, some: F) -> Option where F: FnOnce() -> T, { if self { Some(some()) } else { None } } } pub enum Either { Left(L), Right(R), } fn main() { let q = { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); s.trim_end().to_owned().parse::().unwrap() }; for _ in 0..q { let (a, b) = { let mut s = String::new(); stdin().read_line(&mut s).unwrap(); let s = s.trim_end().to_owned(); let mut s = s.split_whitespace(); ( s.next().unwrap().parse::().unwrap(), s.next().unwrap().parse::().unwrap(), ) }; let ans: Vec = (0..60) .map(|i| Either::Left(i)) .chain((0..60).rev().map(|i| Either::Right(i))) .scan(a, |a, e| { Some(match e { Either::Left(i) => { let x = 1u64 << i; ((*a >> i & 1) == 1 && *a + x <= b).as_some_from(|| { *a += x; x }) } Either::Right(i) => { let x = 1u64 << i; (*a + x <= b).as_some_from(|| { *a += x; x }) } }) }) .filter_map(identity) .collect(); println!("{}", ans.len()); println!( "{}", ans.iter() .map(ToString::to_string) .enumerate() .fold("".to_string(), |acc, (i, s)| if i == 0 { s } else { acc + " " + s.as_str() }) ); } }