Yakumo Yukari is with no doubt one of the most powerful youkai in Gensokyo. Her ability is manipulating boundaries. She has `N` unknown creatures called "sinsack" or "the crime bag" which live in the basement of Yukari's house. Sinsacks are numbered from 1 to `N`. There are `M` rooms with infinite capacity in the basement and each room has two states: available or unavailable. Yukari will reverse the state of consecutive rooms every day. Sinsacks can only live in available rooms. And each available room should contain at least one sinsack.

As a 17-year-old girl, recently Yukari is interested in how many different ways to arrange sinsacks in rooms. At the beginning, all rooms are available. In the following `D` days, Yukari will ask you the number of ways after reversing. Two ways A and B are regarded as the same if for any room in A, there exists a room in B that the sinsacks in these two rooms have the same set of numbers. In other words, rooms are indistinguishable.

The first line of the input contains an integer `T` (`T` ≤ 10), indicating the number of cases. For each test case:

The first line contains three integers `N`, `M` and `D` (1 ≤ `M` ≤ `N`, `D` ≤ 100000). Their meanings are described above.

The following `D` lines each contain two integers `l` and `r` (1 ≤ `l` ≤ `r` ≤ M) denoting the consecutive rooms `l`, `l + 1`, ..., `r` which are reversed by Yukari on that day.

提交代码