Lantern Sparks


Pondo has strung nn lanterns together with mm wires. Lantern ii independently chooses an integer brightness uniformly at random from the inclusive interval [li,ri][l_i, r_i].

A wire connecting lanterns uu and vv produces a spark if at least one of the two brightnesses is divisible by a fixed integer pp. Let XX be the number of wires that spark.

Output the expected value of XX.

It can be shown that the answer can be expressed as a rational number P/QP/Q in lowest terms with QQ coprime to 109+710^9 + 7. Output P⋅Q−1 mod (109+7)P \cdot Q^{-1} \bmod (10^9 + 7).

Input

The first line contains three integers nn, mm, and pp.

Each of the next nn lines contains two integers lil_i and rir_i.

Each of the next mm lines contains two integers uu and vv, describing a wire between lanterns uu and vv.

Lanterns are numbered 11 through nn. The wires form an undirected graph. There are no self-loops, but multiple wires between the same pair of lanterns are allowed; each wire is counted separately.

Output

Print a single integer: the expected number of sparks modulo 109+710^9 + 7.

Constraints

  • 1≤n≤1051 \le n \le 10^5
  • 0≤m≤1050 \le m \le 10^5
  • 1≤p≤1091 \le p \le 10^9
  • 1≤li≤ri≤1091 \le l_i \le r_i \le 10^9
  • 1≤u,v≤n1 \le u, v \le n
  • u≠vu \ne v

Example 1

Input 1
3 3 2
1 2
3 4
5 6
1 2
2 3
3 1
Output 1
250000004
Explanation

Each lantern has brightness even with probability 1/21/2. A wire sparks unless both endpoints are odd, which happens with probability 1/41/4, so each wire sparks with probability 3/43/4. The three wires contribute 9/49/4 in expectation, and 9⋅4−1≡250000004(mod109+7)9 \cdot 4^{-1} \equiv 250000004 \pmod{10^9 + 7}.

The three spark events are dependent because they share lanterns, but the expectation of the sum is still the sum of the expectations.

Example 2

Input 2
2 1 3
1 3
1 2
1 2
Output 2
333333336
Explanation

Lantern 11 fails to be divisible by 33 with probability 2/32/3, and lantern 22 never chooses a multiple of 33. The single wire therefore sparks with probability 1/31/3.

Example 3

Input 3
1 0 1
1 1
Output 3
0
Explanation

There are no wires, so the expected number of sparks is 00.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.