| Kit is a young, obedient Fox who excels in his studies, diligently practices | |
| his hunting skills, and is always friendly. His parents couldn't be prouder! | |
| That is, except for one problem... he refuses to eat his vegetables! | |
| In an effort to improve Kit's diet, his parents have set up a little game for | |
| him to play. They've dug a series of 2**N** \+ 2 small holes in a row on the | |
| ground, and numbered them from 0 to 2**N** \+ 1, from first to last. They've | |
| left the first and last holes empty, and filled the remaining 2**N** holes | |
| with one healthy vegetable each! There are **N** different types of | |
| vegetables, numbered from 1 to **N**, and a vegetable of type **Vi** has | |
| initially been placed into each hole _i_, such that exactly 2 vegetables of | |
| each type were used in total. | |
| Kit must start inside hole 0, and jump forwards from hole to hole until he | |
| reaches hole 2**N** \+ 1. When he's inside any given hole _i_, he's agile | |
| enough to jump to either hole _i_ \+ 1 or directly to hole _i_ \+ 2, but he | |
| can't jump any further than that at once. Whenever he lands in a hole | |
| containing a vegetable, the rules of the game mandate that he must eat it! | |
| Kit has agreed to play this game (not that he has much choice in the matter), | |
| but there's only so much he can take. The vegetables are tolerable as long as | |
| there's variety. He doesn't care how many he has to eat in total, but he | |
| absolutely refuses to eat multiple vegetables of any single type over the | |
| course of the game. In other words, for each vegetable type, he must only | |
| enter _at most_ one of the two holes containing that vegetable on his way from | |
| hole 0 to hole 2**N** \+ 1. | |
| Kit will play the game once per day for a period of **M** days. For some fun | |
| variety, at the start of each day _i_, his parents will swap the contents of | |
| two different holes **Ai** and **Bi**. Then, Kit will play the game using the | |
| current configuration of vegetables. Once he's done, his parents will replace | |
| any vegetables which he had eaten with new vegetables of the same types, thus | |
| resetting the game to the state it was in before Kit played it. | |
| Each day, there might be no acceptable way for Kit to complete the game, or | |
| there might be many different ways for him to do so. Two ways are considered | |
| different if at least one hole is visited in one but not the other. In order | |
| to make the game more exciting for himself, Kit would like to count up the | |
| number of different ways he could potentially complete it each day. However, | |
| that's a lot of big numbers to keep track of, so he's only interested in the | |
| sum of these **M** values when taken modulo 1,000,000,007. Please help him | |
| compute this overall sum! | |
| ### Input | |
| Input begins with an integer **T**, the number of different rows of holes. For | |
| each row of holes, there is first a line containing the space-separated | |
| integers **N** and **M**. There is next a line containing 2**N** space- | |
| separated integers, the _i_th of which is **Vi**. Then **M** lines follow, the | |
| _i_th of which contains the space-separated integers **Ai** and **Bi** | |
| ### Output | |
| For the _i_th row of holes, print a line containing "Case #**i**: " followed | |
| by a single integer, the sum of the **M** days' answers modulo 1,000,000,007. | |
| ### Constraints | |
| 1 ≤ **T** ≤ 30 | |
| 1 ≤ **N, M** ≤ 500,000 | |
| 1 ≤ **Ai**, **Bi** ≤ 2**N** | |
| 1 ≤ **Vi** ≤ **N** | |
| Both the sum of **N** values and the sum of **M** values across all **T** | |
| cases do not exceed 2,000,000. | |
| ### Explanation of Sample | |
| In the first case, both holes 1 and 2 will contain vegetables of type 1 even | |
| after their contents are swapped. There are then 2 different ways for Kit to | |
| validly reach hole 3 from hole 0, visiting either of these sequences of holes: | |
| 0 -> 1 -> 3 | |
| 0 -> 2 -> 3 | |
| He can't quite jump far enough to reach hole 3 directly from hole 0, nor can | |
| he visit both holes 1 and 2, as that would require eating multiple vegetables | |
| of a single type. | |
| In the second case, there are 2 different ways for Kit to validly complete the | |
| game on the first day, and only 1 way on the second day. This results in a | |
| final answer of (2 + 1) modulo 1,000,000,007 = 3. | |