Under construction

Still being built. Things may change

The Missing Pet

Time limit4sMemory limit512 MB

Summary
For each hole on an n by n board, find the expected steps of a random walk from a start cell, given it falls into that hole, modulo 10^9+7.
Level

Hard8 of 10

Topics
Probability, Matrix, Math
Solved
No attempts yet

Problem

You are given an n×nn \times n chessboard, with rows and columns numbered from 1 to nn. Little Q punched several holes in specified locations: the ii-th hole is at (ri,ci)(r_i, c_i).

Little Q also has a pet dog. The dog gets lost on the board at cell (r0,c0)(r_0, c_0). Every second, it moves to a random adjacent cell, and each adjacent cell is chosen with equal probability. Two cells are adjacent if they share an edge. If the dog arrives at a cell with a punched hole, it falls into the hole.

For each hole, what is the expected number of seconds the dog walks on the board, given that it finally falls into this hole? Please help him.

Input

The first line contains an integer TT (1≤T≤201 \leq T \leq 20), the number of test cases. For each test case:

The first line contains two integers nn and kk (2≤n≤2002 \leq n \leq 200, 1≤k≤2001 \leq k \leq 200), the size of the chessboard and the number of holes.

Then kk lines follow. The ii-th of them contains two integers rir_i and cic_i (1≤ri,ci≤n1 \leq r_i, c_i \leq n), the location of the ii-th hole.

The last line of each test case contains two integers r0r_0 and c0c_0 (1≤r0,c0≤n1 \leq r_0, c_0 \leq n), the starting location of the pet.

All holes are distinct, and the pet does not start on a hole. It is guaranteed that max⁡(n,k)>5\max(n, k) > 5 holds in at most one test case.

Output

For each test case, output a single line with kk integers: one per hole, in input order, the expected number of seconds the pet walks before falling into that hole, given that it falls into it. If a hole cannot be reached, print -1 instead.

If a hole is reachable and the reduced fraction of the expected value is pq\frac{p}{q}, print the minimum non-negative integer rr such that q⋅r≡p(mod109+7)q \cdot r \equiv p \pmod{10^9+7}. You may assume such rr always exists.

Examples1

  1. Example 1

    Input
    2
    3 3
    1 1
    1 2
    2 1
    2 2
    5 3
    5 3
    4 1
    3 2
    4 5
    
    Expected output
    -1 4 4
    669185882 381533358 341349117