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