The statement of this problem shares a lot with problem A. The differences are that in this problem, the probability is introduced, and the constraint is different.

A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of n rows and m columns. The rows of the floor are numbered from 1 to n from top to bottom, and columns of the floor are numbered from 1 to m from left to right. The cell on the intersection of the r-th row and the c-th column is denoted as (r,c). The initial position of the robot is (r_b, c_b).

In one second, the robot moves by dr rows and dc columns, that is, after one second, the robot moves from the cell (r, c) to (r + dr, c + dc). Initially dr = 1, dc = 1. If there is a vertical wall (the left or the right walls) in the movement direction, dc is reflected before the movement, so the new value of dc is -dc. And if there is a horizontal wall (the upper or lower walls), dr is reflected before the movement, so the new value of dr is -dr.

Each second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row or the same column as its position. There is only one dirty cell at (r_d, c_d). The job of the robot is to clean that dirty cell. 

After a lot of testings in problem A, the robot is now broken. It cleans the floor as described above, but at each second the cleaning operation is performed with probability \frac p {100} only, and not performed with probability 1 - \frac p {100}. The cleaning or not cleaning outcomes are independent each second.

Given the floor size n and m, the robot's initial position (r_b, c_b) and the dirty cell's position (r_d, c_d), find the expected time for the robot to do its job.

It can be shown that the answer can be expressed as an irreducible fraction \frac x y, where x and y are integers and y not ≡ 0 \pmod{10^9 + 7} . Output the integer equal to x ⋅ y^{-1} mod (10^9 + 7). In other words, output such an integer a that 0 ≤ a < 10^9 + 7 and a ⋅ y ≡ x \pmod {10^9 + 7}.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10). Description of the test cases follows.

A test case consists of only one line, containing n, m, r_b, c_b, r_d, c_d, and p (4 ≤ n ⋅ m ≤ 10^5, n, m ≥ 2, 1 ≤ r_b, r_d ≤ n, 1 ≤ c_b, c_d ≤ m, 1 ≤ p ≤ 99) — the sizes of the room, the initial position of the robot, the position of the dirt cell and the probability of cleaning in percentage.

Output

For each test case, print a single integer — the expected time for the robot to clean the dirty cell, modulo 10^9 + 7.

Example

Input


6
2 2 1 1 2 1 25
3 3 1 2 2 2 25
10 10 1 1 10 10 75
10 10 10 10 1 1 75
5 5 1 3 2 2 10
97 98 3 5 41 43 50


Output


3
3
15
15
332103349
99224487

Note

In the first test case, the robot has the opportunity to clean the dirty cell every second. Using the [geometric distribution](https://en.wikipedia.org/wiki/Geometric_distribution), we can find out that with the success rate of 25\%, the expected number of tries to clear the dirty cell is \frac 1 {0.25} = 4. But because the first moment the robot has the opportunity to clean the cell is before the robot starts moving, the answer is 3.

<image> Illustration for the first example. The blue arc is the robot. The red star is the target dirt cell. The purple square is the initial position of the robot. Each second the robot has an opportunity to clean a row and a column, denoted by yellow stripes.

In the second test case, the board size and the position are different, but the robot still has the opportunity to clean the dirty cell every second, and it has the same probability of cleaning. Therefore the answer is the same as in the first example.

<image> Illustration for the second example.

The third and the fourth case are almost the same. The only difference is that the position of the dirty cell and the robot are swapped. But the movements in both cases are identical, hence the same result.

Source: codeforces | Difficulty: HARD
Tags: Mathematics

Implementation

Probability


Solutions:
import sys
from sys import stdin
import math
mod = 10 ** 9 + 7

def inverse(n, mod):
	return pow(n, mod - 2, mod)
onehand = inverse(100, mod)
tt = int(stdin.readline())
ANS = []
for _ in range(tt):
	(n, m, rb, cb, rd, cd, p) = map(int, stdin.readline().split())
	p = p * onehand % mod
	loop = 2 * (n - 1) * 2 * (m - 1) // math.gcd(2 * (n - 1), 2 * (m - 1))
	xmods = []
	tx = rb
	diffx = 1 if n != 1 else 0
	for i in range(loop):
		if tx == rd:
			xmods.append(i)
		if not 1 <= tx + diffx <= n:
			diffx *= -1
		tx += diffx
	ymods = []
	ty = cb
	diffy = 1 if m != 1 else 0
	for i in range(loop):
		if ty == cd:
			ymods.append(i)
		if not 1 <= ty + diffy <= m:
			diffy *= -1
		ty += diffy
	s = set(xmods)
	for i in ymods:
		s.add(i)
	lis = list(s)
	lis.sort()
	(lasta, lastb) = (0, 1)
	for i in range(len(lis) - 1, -1, -1):
		if i == len(lis) - 1:
			kai = loop - lis[i]
		else:
			kai = lis[i + 1] - lis[i]
		newa = (1 - p) * (lasta + kai) % mod
		newb = (1 - p) * lastb % mod
		if i == 0:
			ans = (newa + lis[0]) * inverse(1 - newb, mod)
			ANS.append(str(ans % mod))
		(lasta, lastb) = (newa, newb)
print('\n'.join(ANS))


I = lambda : [*map(int, input().split())]
(t,) = I()
for _ in range(t):
	(n, m, rb, cb, rd, cd, p) = I()
	if rd >= rb:
		row1 = rd - rb
		row2 = 2 * n - rd - rb
	else:
		row1 = 2 * n - rd - rb
		row2 = 2 * n - 2 + rd - rb
	if cd >= cb:
		col1 = cd - cb
		col2 = 2 * m - cd - cb
	else:
		col1 = 2 * m - cd - cb
		col2 = 2 * m - 2 + cd - cb
	times = []
	x = 2 * n - 2
	y = 2 * m - 2
	row1 %= x
	row2 %= x
	col1 %= y
	col2 %= y
	g = x * y
	for i in range(g // x):
		times.append(row1 + x * i)
		times.append(row2 + x * i)
	for i in range(g // y):
		times.append(col1 + y * i)
		times.append(col2 + y * i)
	times = sorted(list(set(times)))
	mod = 10 ** 9 + 7
	l = len(times)
	denom = (pow(100, l, mod) - pow(100 - p, l, mod)) % mod
	inv = pow(100, mod - 2, mod)
	num = 0
	power = pow(100, l - 1, mod)
	for i in range(l):
		num += times[i] * p * power % mod
		power = power * (100 - p) * inv % mod
	num += g * pow(100, l, mod)
	num -= g * denom
	num %= mod
	print(num * pow(denom, mod - 2, mod) % mod)


from sys import stdin, stdout
N = 10 ** 9 + 7

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a, m=N):
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m
inv100 = modinv(100)
t = int(stdin.readline())
for _ in range(t):
	(n, m, x, y, x_t, y_t, p) = [int(z) for z in stdin.readline().split()]
	p = p * inv100 % N
	if x_t == 1 or x_t == n:
		time_x_buffer = [2 * (n - 1), 2 * (n - 1)]
	else:
		time_x_buffer = [2 * (x_t - 1), 2 * (n - x_t)]
	if x <= x_t:
		time_x = x_t - x
		time_x_buffer_pointer = 1
	else:
		time_x = n - x + (n - x_t)
		time_x_buffer_pointer = 0
	if y_t == 1 or y_t == m:
		time_y_buffer = [2 * (m - 1), 2 * (m - 1)]
	else:
		time_y_buffer = [2 * (y_t - 1), 2 * (m - y_t)]
	if y <= y_t:
		time_y = y_t - y
		time_y_buffer_pointer = 1
	else:
		time_y = m - y + (m - y_t)
		time_y_buffer_pointer = 0
	expression = 0
	coefficient = p
	while min(time_x, time_y) < 4 * (n - 1) * (m - 1):
		if time_x == time_y:
			expression = (expression + coefficient * time_x) % N
			coefficient = coefficient * (1 - p) % N
			time_x += time_x_buffer[time_x_buffer_pointer]
			time_x_buffer_pointer = 1 - time_x_buffer_pointer
			time_y += time_y_buffer[time_y_buffer_pointer]
			time_y_buffer_pointer = 1 - time_y_buffer_pointer
		elif time_x < time_y:
			expression = (expression + coefficient * time_x) % N
			coefficient = coefficient * (1 - p) % N
			time_x += time_x_buffer[time_x_buffer_pointer]
			time_x_buffer_pointer = 1 - time_x_buffer_pointer
		else:
			expression = (expression + coefficient * time_y) % N
			coefficient = coefficient * (1 - p) % N
			time_y += time_y_buffer[time_y_buffer_pointer]
			time_y_buffer_pointer = 1 - time_y_buffer_pointer
	coefficient = coefficient * modinv(p) % N
	answer = (expression + coefficient * 4 * (n - 1) * (m - 1)) % N * modinv((1 - coefficient) % N) % N
	stdout.write(str(answer) + '\n')


import io, os, sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
output = sys.stdout.write
DEBUG = os.environ.get('debug') is not None
if DEBUG:
	from inspect import currentframe, getframeinfo
	from re import search

def debug(*args):
	if not DEBUG:
		return
	frame = currentframe().f_back
	s = getframeinfo(frame).code_context[0]
	r = search('\\((.*)\\)', s).group(1)
	vnames = r.split(', ')
	var_and_vals = [f'{var}={val}' for (var, val) in zip(vnames, args)]
	prefix = f'{currentframe().f_back.f_lineno:02d}: '
	print(f"{prefix}{', '.join(var_and_vals)}")
INF = float('inf')
MOD = 10 ** 9 + 7

def mod_inv(a, p):
	return pow(a, p - 2, p)

def mod_div(a, b, p):
	return a * mod_inv(b, p) % p

def solve(R, C, r1, c1, r2, c2, p):
	p = mod_div(p, 100, MOD)
	dists = []
	(d, dr, dc) = (0, 1, 1)
	seen = set()
	while True:
		if not 1 <= r1 + dr <= R:
			dr = -dr
		if not 1 <= c1 + dc <= C:
			dc = -dc
		if (r1, c1, dr, dc) in seen:
			dists.append(d)
			break
		if r1 == r2 or c1 == c2:
			dists.append(d)
			d = 0
		seen.add((r1, c1, dr, dc))
		r1 += dr
		c1 += dc
		d += 1
	(S, m) = (0, 1)
	for d in dists:
		S += d * m
		m *= 1 - p
		m %= MOD
	m = mod_div(m, 1 - p, MOD)
	return mod_div(S, 1 - m, MOD)

def main():
	T = int(input())
	for _ in range(T):
		(R, C, r1, c1, r2, c2, p) = list(map(int, input().split()))
		out = solve(R, C, r1, c1, r2, c2, p)
		output(f'{out}\n')
main()