#P50128. 「LibreOJ Round #8」Moejy0viiiiiv's Red Envelopes

「LibreOJ Round #8」Moejy0viiiiiv's Red Envelopes

Description

Moejy0viiiiiv is collecting red envelopes on a rectangular plane. She starts at (0,0)(0,0). Every day at noon, she walks from (x,y)(x, y) to (x,y+1)(x,y+1) with probability A/1996488707A/1996488707, and to (x+1,y)(x+1,y) with probability B/1996488707B/1996488707, and stops immediately with probability 1A/1996488707B/19964887071-A/1996488707-B/1996488707 (once she stops, she will never move again). Besides, she also stops after walking for NN days.

With a given constant integer DD, there’s a red envelope at each (xD,yD)(0x,y)(xD, yD)(0 \leq x, y). There’re also KK barriers at (x1,y1),(x2,y2),(x3,y3),...,(xK,yK)(x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_K, y_K) (barriers never coincide with red envelopes). If she walks to a barrier, she will stop immediately.

Moejy0viiiiiv will collect each red envelope she passes by (including (0,0)(0,0)). What’s the expected number of red envelopes Moejy0viiiiiv collects after NN days? Output the answer mod998244353\bmod 998244353. Notice that 1996488707mod998244353=11996488707 \bmod 998244353 = 1.

Input Format

The first line contains two positive integers A,BA,B.

The second line contains four positive integers N,D,M,KN,D,M,K.

The following KK lines each contains two integers, the i+2i+2-th line contains xi,yix_i,y_i.

Output Format

Output contains one integer, the expected number of red envelopes mod998244353\bmod 998244353.

Sample 1

1 1
2 2 5 1
1 0
2

There’re three red envelopes satisfies x+yNx+y\le N, (0,0),(0,2),(2,0)(0, 0), (0, 2), (2, 0). As there’s a barrier at (1,0)(1, 0), the red envelope at (2,0)(2, 0) is unreachable. The probability of getting the other two red envelopes are both 11.

A+BA+B doesn’t need to be 11.

1 2
2 2 5 0
6

Constraints

For all test cases, 1N1018,0K50,1D,M1000,0x1,x2,...,xKM1 \leq N \leq 10^{18}, 0 \leq K \leq 50, 1 \leq D, M \leq 1000, 0 \leq x_1, x_2, ..., x_K \leq M, i{1,2,3,...,K},DxiDyi,xi+yiN,0A,B<998244353\forall i \in \{1, 2, 3, ..., K\}, D \nmid x_i \vee D \nmid y_i, x_i + y_i \leq N, 0 \leq A, B < 998244353.

Detailed constraints are as follows (blank grids denote the same constraints as mentioned above):

Subtask # Score (percentage) NN DD MM KK
11 99 104\le 10^4 -
22 1212 105\le 10^5 10\le 10 00
33 2727 -
44 88 105\le 10^5 10\le 10 10\le 10 -
55 4444 -