human
Give me a Python code to print the minimum distance you should move the first table, or -1 if there is no way to free enough space for the second table given the following:
You have an axis-aligned rectangle room with width W and height H, so the lower left corner is in point (0, 0) and the upper right corner is in (W, H).

There is a rectangular table standing in this room. The sides of the table are parallel to the walls, the lower left corner is in (x_1, y_1), and the upper right corner in (x_2, y_2).

You want to place another rectangular table in this room with width w and height h with the width of the table parallel to the width of the room.

The problem is that sometimes there is not enough space to place the second table without intersecting with the first one (there are no problems with tables touching, though).

You can't rotate any of the tables, but you can move the first table inside the room. 

 Example of how you may move the first table.

What is the minimum distance you should move the first table to free enough space for the second one?

Input

The first line contains the single integer t (1 ≤ t ≤ 5000) — the number of the test cases.

The first line of each test case contains two integers W and H (1 ≤ W, H ≤ 10^8) — the width and the height of the room.

The second line contains four integers x_1, y_1, x_2 and y_2 (0 ≤ x_1 < x_2 ≤ W.
0 ≤ y_1 < y_2 ≤ H) — the coordinates of the corners of the first table.

The third line contains two integers w and h (1 ≤ w ≤ W.
1 ≤ h ≤ H) — the width and the height of the second table.

Output

For each test case, print the minimum distance you should move the first table, or -1 if there is no way to free enough space for the second table.

Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}.

Example

Input

5
8 5
2 1 7 4
4 2
5 4
2 2 5 4
3 3
1 8
0 3 1 6
1 5
8 1
3 0 6 1
5 1
8 10
4 5 7 8
8 5

Output

1.000000000
-1
2.000000000
2.000000000
0.000000000

Note

The configuration of the first test case is shown in the picture. But the movement of the first table is not optimal. One of the optimal movement, for example, is to move the table by (0, -1), so the lower left corner...
Solve the task in PYTHON3.
assistant
#Here is Python code to print the minimum distance you should move the first table, or -1 if there is no way to free enough space for the second table.

from sys import stdin, stdout, setrecursionlimit as srl
from threading import stack_size
from collections import deque, defaultdict as dd
from math import gcd, ceil, sqrt
from bisect import bisect_left as lb
from bisect import bisect_right as rb

#srl(int(1e6))
input = stdin.readline
flush = stdout.flush

tc = 1
tc = int(input())
for _ in range(tc):
    W, H = map(int, input().split())
    x1, y1, x2, y2 = map(int, input().split())
    w1 = x2 - x1
    h1 = y2 - y1
    w2, h2 = map(int, input().split())
    def dis(a, b):
        f = float('inf')
        if (w1+w2 <= W):
            f = min(f, abs(a[0]-b[0]))
        if (h1+h2 <= H):
            f = min(f, abs(a[1]-b[1]))
        return f
    if (h1 + h2 > H and w1 + w2 > W):
        print(-1)
        continue
    ans = float('inf')
    #tl
    x = w2
    y = H - h2
    if (x1 > x or y2 < y):
        print(0)
        continue
    else:
        ans = min(ans, dis([x1, y2], [x, y]))
    #tr
    x = W - w2
    y = H - h2
    if (x2 < x or y2 < y):
        print(0)
        continue
    else:
        ans = min(ans, dis([x2, y2], [x, y]))
    #bl
    x = w2
    y = h2
    if (x1 > x or y1 > y):
        print(0)
        continue
    else:
        ans = min(ans, dis([x1, y1], [x, y]))
    #br
    x = W - w2
    y = h2
    if (x2 < x or y1 > y):
        print(0)
        continue
    else:
        ans = min(ans, dis([x2, y1], [x, y]))
    if (ans == float('inf')):
        ans = -1
    print(ans)