for _ in range(int(input())): n, m, l, r = map(int, input().split()) print((r - l + n - 1) // (n - 1) * (m + 1) % 998244353)