Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

binary search

brute force

data structures

hashing

strings

*1600

No tag edit access

The problem statement has recently been changed. View the changes.

×
C. Binary String Copying

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given a string $$$s$$$ consisting of $$$n$$$ characters 0 and/or 1.

You make $$$m$$$ copies of this string, let the $$$i$$$-th copy be the string $$$t_i$$$. Then you perform exactly one operation on each of the copies: for the $$$i$$$-th copy, you sort its substring $$$[l_i; r_i]$$$ (the substring from the $$$l_i$$$-th character to the $$$r_i$$$-th character, both endpoints inclusive). Note that each operation affects only one copy, and each copy is affected by only one operation.

Your task is to calculate the number of different strings among $$$t_1, t_2, \ldots, t_m$$$. Note that the initial string $$$s$$$ should be counted only if at least one of the copies stays the same after the operation.

Input

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

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of $$$s$$$ and the number of copies, respectively.

The second line contains $$$n$$$ characters 0 and/or 1 — the string $$$s$$$.

Then $$$m$$$ lines follow. The $$$i$$$-th of them contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) — the description of the operation applied to the $$$i$$$-th copy.

The sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$. The sum of $$$m$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Output

Print one integer — the number of different strings among $$$t_1, t_2, \ldots, t_m$$$.

Example

Input

36 51011001 21 32 45 51 66 41001112 21 41 31 21 101 1

Output

3 3 1

Note

Consider the first example. Copies below are given in order of the input operations. Underlined substrings are substrings that are sorted:

- 101100 $$$\rightarrow$$$ 011100;
- 101100 $$$\rightarrow$$$ 011100;
- 101100 $$$\rightarrow$$$ 101100;
- 101100 $$$\rightarrow$$$ 101100;
- 101100 $$$\rightarrow$$$ 000111.

There are three different strings among $$$t_1, t_2, t_3, t_4, t_5$$$: 000111, 011100 and 101100.

Consider the second example:

- 100111 $$$\rightarrow$$$ 100111;
- 100111 $$$\rightarrow$$$ 001111;
- 100111 $$$\rightarrow$$$ 001111;
- 100111 $$$\rightarrow$$$ 010111.

There are three different strings among $$$t_1, t_2, t_3, t_4$$$: 001111, 010111 and 100111.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/19/2024 19:02:51 (j3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|