#Lutece1501. Hazy String

Hazy String

Migrated from Lutece 1501 H

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Archaeologists find an ancient string on a monument, but some characters have become hazy with the passage of time, and we only know the remain characters.

Now archaeologists want to re-build the string, and know two rules:

  • there is no palindrome substring in the original string. Note that a single character is not regarded as a palindrome string here.
  • the character set size of the original string is KK.
  • 00\le the character of the original string <K<K.

Please calculate the number of original string which satisfy above rules.

Input

First line contains an integer TT (1T1001\le T\le 100), which indicates the number of test cases.

Every test case begins with three integers NN, KK and LL ($0\le N\le 2000,1\le K\le 10^9,\max(1,N)\le L\le 10^9$), which is the number of known characters, the character set size of the original string and the length of the original string.

Then NN lines follow, the ii-th line contains two integers pip_i and viv_i (0pi<pi+1<L,0vi<K0 \leq p_i < p_{i+1} <L,0\le v_i<K), means the position and value of ii-th known character.

For 90%90\% of the use cases, N10N\le 10 holds.

Output

For every test case, you should output Case #x: y, where x indicates the case number and counts from 11 and y is the result.

Because y could be very large, just mod it with 109+710^9+7.

Samples

3
0 3 4
1 4 4
1 1
2 5 5
1 1
3 2
Case #1: 6
Case #2: 12
Case #3: 27

Resources

第二届中国大学生程序设计竞赛 杭州站(CCPC 2016 Hangzhou Site)