logo AlgoBeat OnlineJudge
登录 注册

#208812. [ICPC 2022 Xi'an R] Square Grid

内存限制:512 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Given a square grid, its lattice points labeled from to , and a number .

You need to answer queries in this format: given and , how many ways are there to move from to in exactly steps so that in each step you move from a lattice point to one of its neighbors (up, down, left, right). Calculate the answer modulo .

输入格式

The first line contains three integers (), () and ().

Each of the following lines contains four integers , , and (), representing a query.

输出格式

For each query, output a line containing one integer, representing the answer to the query modulo .

样例

样例输入 1

2 5 3
0 0 1 2
1 1 2 1
0 0 2 2

样例输出 1

30
64
0

样例输入 2

5 20 5
0 0 5 5
1 1 4 4
2 2 3 3
2 3 2 3
1 2 5 2

样例输出 2

615136704
443203969
899931333
464755094
679729107

数据范围与提示

Source: The 2022 ICPC Asia Xi'an Regional Contest Problem I.

Author: djq_cpp.