import sys from collections import deque, Counter sys.setrecursionlimit(5 * 10 ** 5) from pypyjit import set_param set_param('max_unroll_recursion=-1') input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 for _ in range(ii()): n, x = mi() k = n // x ans = 0 ans += (k + 1) // 2 n -= n // x ans += n // 2 ans %= mod print(ans)