const MOD: usize = 998244353; fn solve() -> usize { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = temp[0]; let x = temp[1]; let cnt = n / x; let mut ret = if x % 2 == 0 { cnt * x / 2 } else if cnt % 2 == 0 { cnt * x / 2 } else { cnt * x / 2 + 1 }; if n - cnt * x > 0 { ret += (n - cnt * x) / 2; if (n - cnt * x) % 2 == 1 { if cnt % 2 == 0 { ret += 1; } } } ret } fn main() { let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t: usize = t.trim().parse().unwrap(); let mut result = Vec::with_capacity(t); for _ in 0..t { result.push(solve()); } for &v in result.iter() { println!("{}", v % MOD); } }