description: 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. 
  
  <image> 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 will move from (2, 1) to (2, 0). Then you can place the second table at (0, 3)-(4, 5).
  
  In the second test case, there is no way to fit both tables in the room without intersecting.
  
  In the third test case, you can move the first table by (0, 2), so the lower left corner will move from (0, 3) to (0, 5).
solution: import java.io.*;
  import java.util.*;
  
  public class codeforce {
  
      static class Reader {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Reader()
          {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Reader(String file_name) throws IOException
          {
              din = new DataInputStream(
                      new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException
          {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      }
                      else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte)c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextInt() throws IOException
          {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          public long nextLong() throws IOException
          {
              long ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg)
                  return -ret;
              return ret;
          }
  
          public double nextDouble() throws IOException
          {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
  
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          private void fillBuffer() throws IOException
          {
              bytesRead = din.read(buffer, bufferPointer = 0,
                      BUFFER_SIZE);
              if (bytesRead == -1)
                  buffer[0] = -1;
          }
  
          private byte read() throws IOException
          {
              if (bufferPointer == bytesRead)
                  fillBuffer();
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException
          {
              if (din == null)
                  return;
              din.close();
          }
      }
      static int mod = (int) (1e9 + 7);
  
      public static class pair implements Comparator<pair> {
          int x;
          int y;
  
          public pair() {
  
          }
  
          public pair(int x, int y) {
              this.x = x;
              this.y = y;
  
          }
  
          @Override
          public int compare(pair o1, pair o2) {
              return o1.y - o2.y;
          }
      }
      public static long modularpow(long a,long b){
          long res=1;
          if(b==0)
              return res;
          else
          {
              while(b>0){
                  if(b%2==1){
                      res*=a;
                      res%=mod;
  
                  }
                  a=a*a;
                  a%=mod;
                  b/=2;
              }
              return res%mod;
          }
      }
      public static int gcd(int a,int b){
          if(b==0)
              return a;
          else
              return gcd(b,a%b);
      }
      public static String binary(int a){
          String s1="";
          while(a>0){
              s1=a%2+s1;
              a/=2;
          }
          return s1;
      }
      public static int Lower_Bound(long a[],int l,int r,long k){
  
  
          while(r-l>1){
              int mid=l+(r-l)/2;
              if(a[mid]<=k) l=mid;
              else
                  r=mid;
  
          }
          return l;
      }
      public static int Upper_Bound(int a[],int l,int r,int k){
  
          while(r-l>1){
              int mid=(l+r)/2;
              if(a[mid]<=k)
                  l=mid;
              else
                  r=mid;
          }
          return l+1;
      }
      public static void main(String arg[]) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        StringBuilder sb=new StringBuilder();
        while(t-->0){
             String s[]=br.readLine().split(" ");
            int x=Integer.parseInt(s[0]);
             int y=Integer.parseInt(s[1]);
             s=br.readLine().split(" ");
             int x1=Integer.parseInt(s[0]);
             int y1=Integer.parseInt(s[1]);
             int x2=Integer.parseInt(s[2]);
             int y2=Integer.parseInt(s[3]);
             s=br.readLine().split(" ");
             int w=Integer.parseInt(s[0]);
             int h=Integer.parseInt(s[1]);
             int ans=Integer.MAX_VALUE;
             if(x2-x1+w<=x){
                 ans=Math.min(ans,Math.max(0,w-x1));
                 ans=Math.min(ans,Math.max(0,x2-(x-w)));
  
             }
             if(y2-y1+h<=y){
                 ans=Math.min(ans,Math.max(0,h-y1));
                 ans=Math.min(ans,Math.max(0,y2-(y-h)));
             }
             if(ans==Integer.MAX_VALUE)
                 sb.append("-1\n");
             else
                 sb.append(String.format("%.9f",(double)ans)+"\n");
            }
        System.out.println(sb);
      }
  }
  
  