Bitwise Subsegment Exclusion#13086

Bitwise Subsegment Exclusion

2 seconds
256 megabytes

You are given a binary array of length , where each element a_i \in \{0, 1\}.

You need to answer independent queries. In each query, you are given a range [l, r] (1 \le l \le r \le n).

For any binary sequence b = [b_1, b_2, \dots, b_k] of length k \ge 1, its numerical value is defined by implicitly prepending a '1' bit to the sequence. Formally, the value is calculated as:

val(b) = 2^k + \sum_{i=1}^{k} b_i \cdot 2^{k - i}

For example:

For each query [l, r], your task is to find a binary sequence that does NOT appear as a contiguous subsegment in the subarray a[l \dots r] such that val(b) is strictly minimized.

Output this minimum value modulo .

Input

The first line contains a single integer (1 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers and (1 \le n, q \le 2 \cdot 10^5) — the length of the binary array and the number of queries.

The second line of each test case contains space-separated integers a_1, a_2, \dots, a_n (a_i \in \{0, 1\}) — the elements of the array.

The next lines describe the queries. Each line contains two integers and (1 \le l \le r \le n) — the boundaries of the query range.

It is guaranteed that both the sum of and the sum of over all test cases do not exceed 2 \cdot 10^5.

Output

For each query, output a single integer on a new line — the minimum numerical value of a binary sequence that does not appear as a contiguous subsegment in a[l \dots r], modulo .

Examples

Example 1

Loading
Loading

Note

In the first test case, the array is a = [0, 1, 0].

  • In the first query , the contiguous subsegments present are [0], [1], [0, 1], [1, 0], and [0, 1, 0]. Their respective decimal values are 2, 3, 5, 6, and . The smallest value that is not formed is , which corresponds to the sequence .

  • In the second query , the subarray is . The subsegments present are [0], [1], and . The smallest missing value is again (sequence ).

  • In the third query , the subarray is . The only subsegment present is (value ). The smallest missing value is (sequence ).

In the second test case, the array is a = [1, 1, 1, 1]. For the query , the sequence (value ) never appears, so the answer is .

In the third test case, the array is a = [1, 0, 0, 1].

  • For the query , the subarray is [1, 0, 0]. It contains [0], [1], [0, 0], [1, 0] (values 2, 3, 4, 6). The smallest missing value is (sequence ).

  • For the query , the subarray is [0, 0, 1]. It contains [0], [1], [0, 0], [0, 1] (values 2, 3, 4, 5). The smallest missing value is (sequence ).

  • For the query , the subarray contains values 2, 3, 4, 5, and . The smallest missing value is (sequence ).

Scoring

  • Subtask 1 (100 points): \sum n \le 2000 and \sum q \le 2000.

  • Subtask 2 (150 points): \sum n \le 40000 and \sum q \le 40000.

  • Subtask 3 (250 points): No additional constraints.