#P7493. [传智杯 #3 决赛] 旅人1969

[传智杯 #3 决赛] 旅人1969

Description

On a straight road, there are nn hotels. The coordinate of the ii-th hotel is ii. Every morning, you start from a hotel and can walk a maximum distance of mm. You are also given a fixed constant kk.

You are given qq queries. In each query, given u,vu, v, find the number of plans to start in the morning from hotel uu to hotel vv, passing through at most kk hotels (excluding the start point uu) and keeping the walking direction unchanged. Two plans are different if and only if there exists a different choice of a hotel. The answer should be taken modulo 998244353998244353.

For all testdata, n,q105n, q \leq 10^5, m,k104m, k \leq 10^4, mk105mk \leq 10^5, and u,vnu, v \leq n.

Input Format

The input has q+1q + 1 lines.

The first line contains 44 positive integers n,m,k,qn, m, k, q.

The next qq lines each contain 22 positive integers u,vu, v, representing a query.

Output Format

Output qq lines, each containing 11 integer, representing the answer.

3 2 2 2
1 3
2 3
2
1
2077 30 200 3
1949 2021
1969 2077
1970 2004

360658315
804081653
603979748

Hint

Translated by ChatGPT 5