Read problems statements in Mandarin Chinese  and Russian. 

Little Elephant from Zoo of Lviv likes to paint.

He has n objects to paint, ordered in a row and numbered form left to right starting from 1. There are totally c colors, numbered from 0 to c-1. At the beggining all objects are colored in color with number 1. When object with color a is painted in color b, the resulting color will have number (a*b) mod c.

Little Elephant is going to make k turns. At i-th (0-based numeration) turn he will randomly choose any subset (even empty) of objects with indices in range [L_{i}; R_{i}] (inclusive) and paint all objects in chosen subset with random color (the same for all objects in the subset).

Little Elephant wants to know the expected sum of all colors over all n objects after making all k turns. Help him.

------ Input ------ 

First line contain single integer T - the number of test cases. T test cases follow. First line of each test case contains three integers n, c and k. Next k lines of each test case contain k pairs of integers L_{i} and R_{i}, one pair per line.

------ Output ------ 

In T lines print T real numbers - the answers for the corresponding test cases.

Any results within 10^-6 absolute error will be accepted.

------ Constraints ------ 

1 ≤ T ≤ 10

1 ≤ n, k ≤ 50

2 ≤ c ≤ 100

1 ≤ L_{i} ≤ R_{i} ≤ n

----- Sample Input 1 ------ 
2
4 3 4
1 2
2 4
3 3
1 4
7 10 7
7 7
3 4
1 2
5 5
4 5
2 7
3 3
----- Sample Output 1 ------ 
3.444444444
22.943125000

Difficulty: HARD

Solutions:
nck = [[0 for x in range(0, 102)] for x in range(0, 102)]

def precompute():
	for i in range(0, 102):
		for j in range(0, 102):
			if j == 0 or i == j:
				nck[i][j] = 1
			else:
				nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j]
precompute()
test = int(input())
while test:
	color = [[0 for x in range(0, 102)] for x in range(0, 52)]
	csum = [0 for x in range(0, 52)]
	count = [0 for x in range(0, 102)]
	csum[0] = 1
	ans = 0
	(n, c, k) = input().split()
	n = int(n)
	c = int(c)
	k = int(k)
	for i in range(0, c):
		color[1][i] = 1
		csum[1] += i / c
	for i in range(2, 51):
		for j in range(0, c):
			for kk in range(0, c):
				col = j * kk % c
				color[i][col] += color[i - 1][j]
		for j in range(0, c):
			csum[i] += j * color[i][j]
		csum[i] /= pow(c, i)
	for i in range(0, k):
		(l, r) = input().split()
		l = int(l)
		r = int(r)
		for j in range(l, r + 1):
			count[j] += 1
	for i in range(1, n + 1):
		temp = 0.0
		ctr = count[i]
		for j in range(0, ctr + 1):
			temp += nck[ctr][j] / pow(2, ctr) * csum[j]
		ans += temp
	print('{0:.9f}'.format(ans))
	test = test - 1