logo AlgoBeat OnlineJudge
登录 注册

#217105. [ICPC 2017 Xi'an R] Acedia

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

题目描述

You are given a sequence of numbers, the -th number is .

You need to answer queries.

Each query is: for each from to , calculate the number of valid pairs in range .

We call a pair valid when:

  1. For each from to , there exists at least one element in range which is equal to .
  2. There is no element in range which is equal to or .

输入格式

The input contains multiple test cases.

The first line contains a number denoting the number of test cases.

In each test case:

The first line contains two numbers . .

Then one line contains numbers indicating .

The following lines each contain two numbers denoting a query in range .

输出格式

For each query you need to output numbers. In order to reduce the amount of output, you just need to output each number mod , without space.

For each test case, output lines. The -th line contains a string of length indicating the answers of the -th query.

样例

样例输入 1

1
5 5
1 2 4 5 6
1 5
1 2
3 4
3 5
4 5

样例输出 1

0110000000
0100000000
0100000000
0010000000
0100000000