Habbab thinks that this problem is very easy, so are you going to be '3rrar' and run away from us without solving it, or 'lesa al-amana momkenah'?
You are given a binary array $$$a$$$ of length $$$n$$$, and $$$q$$$ queries. Each query provides a range $$$[l, r]$$$, corresponding to the subarray $$$b = a_l, a_{l+1}, \dots, a_r$$$ of length $$$m = r - l + 1$$$.
For each query, calculate the number of good cyclic shifts$$$^\dagger$$$ of $$$b$$$.
A binary array $$$c$$$ of length $$$m$$$ is considered good if the following process finishes with $$$x = 0$$$:
$$$^\dagger$$$ A cyclic shift of $$$b$$$ is formed by moving its first $$$k$$$ elements to the end ($$$0 \le k \lt m$$$), resulting in the array $$$b_{k+1}, \dots, b_m, b_1, \dots, b_k$$$. All $$$m$$$ possible shifts are counted independently for each query, even if they result in identical arrays.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
Each test case begins with a line containing two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the length of the array and the number of queries.
The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$).
Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$), describing a query.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$, and the sum of $$$q$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For every query, print one integer — the number of good cyclic shifts of the subarray in that query.
25 41 0 1 0 11 52 41 14 56 40 0 0 1 1 01 61 34 53 6
21014323
Consider the first test case.