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.util.*;
  import java.util.function.Function;
  import java.util.stream.Collectors;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.*;
  import java.math.*;
  
  
  
  
  
  public class Main{
  	static StringBuilder sb;
  	static dsu dsu;
  	static long fact[];
  	static long mod=(long)(1e9+7);
  	static ArrayList<Integer>prime;
  	static long A[];
  	static ArrayList<Integer>adj[];
  	 
  	static void solve()
      {
  		long W=l();long H=l();long x1=l();
  		long y1=l();long x2=l();long y2=l();
  		long w=i();
  		long h=i();
  		int flag=-1;
  		long currv=Long.MIN_VALUE;
  		long currh=Long.MIN_VALUE;
  		long curr=Long.MAX_VALUE;
  		if(y2-y1+h<=H)
          {
              currv=Math.max(h-Math.max(y1,H-y2),(long)0);
              flag=1;
              if(x2-x1+w<=W)
              {
                  currh=Math.max(w-Math.max(x1,W-x2),(long)0);
                  curr=Math.min(currh,currv);
              }
              else
              {
                  curr=currv;
              }
          }
          if(x2-x1+w<=W)
          {
              currh=Math.max(w-Math.max(x1,W-x2),(long)0);
              flag=1;
              if(y2-y1+h<=H)
              {
                  currv=Math.max(h-Math.max(y1,H-y2),(long)0);
                  curr=Math.min(currh,currv);
              }
              else
              {
                  curr=currh;
              }
          }
          if(flag==-1)
          {
          	System.out.println(-1);
          }
          else
          {
          	 double ans =(double)curr;
          	System.out.println(ans);
          }
  		
  		
  		
      }
  	public static void main(String[] args)
  	 {
  		 sb=new StringBuilder();
  	     int test=i();
  	    for(int tt=1;tt<=test;tt++) 
  	    {
  	         solve();
  	    }
  	    System.out.println(sb);
  	 }
  	 
  //*******************************************NCR%P*******************************************************	 
  	 static long ncr(int n, int r)
  	 {
  		 if(r>n)
  			 return (long)0;
  		 
  		 long res=fact[n]%mod;
  		 //System.out.println(res);
  		 res=((long)(res%mod)*(long)(p(fact[r],mod-2)%mod))%mod;
  		 res=((long)(res%mod)*(long)(p(fact[n-r],mod-2)%mod))%mod;
  		 //System.out.println(res);
  		 return res;
  		
  		 
  	 }
  		static long p(long x, long y)//POWER FXN //
  		{
  			if(y==0)
  				return 1;
  			
  			long res=1;
  			while(y>0)
  			{
  				if(y%2==1)
  				{
  					res=(res*x)%mod;
  					y--;
  				}
  				
  				x=(x*x)%mod;
  				y=y/2;
  				
  				
  			}
  			return res;
  		}
  		static long ceil(long num, long den)
  		{
  			return (long)(num+den-1)/den;
  		}
  		
  
  //*******************************************END*******************************************************
  		static int LowerBound(long a[], long x, int i, int j) 
  		{ 
  			//X is the key value
  			int l=i;int r=j;
  			int lb=-1;
  			  while(l<=r)
  			  {
  			    int m=(l+r)/2;
  			    
  			    if(a[m]>=x) 
  			    {
  			    	lb=m;
  			    	r=m-1;
  			    }
  			    else l=m+1;
  			  }
  			  return lb;
  		}
  		static int UpperBound(long a[], long x, int i, int j) 
  		{// x is the key or target value
  		    int l=i,r=j;
  		    int ans=-1;
  		    while(l<=r)
  		    {
  		       int m=(l+r)/2;
  		       
  		       if(a[m]<=x) 
  		       {
  		    	   ans=m;
  		    	   l=m+1;
  		       }
  		       else r=m-1;
  		    }
  		    return ans;
  		 }
  		
  		
  		
  	 
  	 
  	 //*********************************Disjoint set union*************************//
  	 static class dsu
  	 {
  		 int parent[];
  		 dsu(int n)
  		 {
  			 parent=new int[n+1];
  			 for(int i=0;i<=n;i++)
  				 parent[i]=-1;
  		 }
  		 int find(int a)
  		 {
  			 if(parent[a]<0)
  				 return a;
  			 else
  			 {
  				 int x=find(parent[a]);
  				 parent[a]=x;
  				 return x;
  			 }
  		 }
  		 void merge(int a,int b)
  		 {
  			 a=find(a);
  			 b=find(b);
  			 if(a==b)
  				 return;
  			 parent[b]=a;
  		 }
  	 }
  	 
  	 
  	 
  //*******************************************PRIME FACTORIZE *****************************************************************************************************//
  	 static TreeMap<Integer,Integer> prime(long n)
  	 {
  		 TreeMap<Integer,Integer>h=new TreeMap<>();
  		 long num=n;
  		 for(int i=2;i<=Math.sqrt(num);i++)
  		 {
  			 if(n%i==0)
  			 {
  				 int nt=0;
  				 while(n%i==0) {
  					 n=n/i;
  					 nt++;
  				 }
  				 h.put(i, nt);
  			 }
  		 }
  		 if(n!=1)
  			 h.put((int)n, 1);
  		 return h;
  		 
  	 }
  	 
  	
  	
  //*************CLASS PAIR ***********************************************************************************************************************************************
  	    static class pair implements Comparable<pair>
  	    {
  	        int x;
  	        int y;
  	       
  	        pair(int x, int y)
  	        {
  	            this.x = x;
  	            this.y = y;
  	        }
  	        public int compareTo(pair o)
  	        {
  	        	return(int)(x-o.x);
  	        	
  	        }
  	       
  	       
  	    }
  //*************CLASS PAIR *****************************************************************************************************************************************************
  	
  	
  	
  
      static class InputReader {
          private InputStream stream;
          private byte[] buf = new byte[1024];
          private int curChar;
          private int numChars;
          private SpaceCharFilter filter;
  
          public InputReader(InputStream stream) {
              this.stream = stream;
          }
  
          public int read() {
              if (numChars == -1)
                  throw new InputMismatchException();
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
                  } catch (IOException e) {
                      throw new InputMismatchException();
                  }
                  if (numChars <= 0)
                      return -1;
              }
              return buf[curChar++];
          }
  
          public int Int() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = read();
              }
              int res = 0;
              do {
                  if (c < '0' || c > '9')
                      throw new InputMismatchException();
                  res *= 10;
                  res += c - '0';
                  c = read();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public String String() {
              int c = read();
              while (isSpaceChar(c))
                  c = read();
              StringBuilder res = new StringBuilder();
              do {
                  res.appendCodePoint(c);
                  c = read();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
          public boolean isSpaceChar(int c) {
              if (filter != null)
                  return filter.isSpaceChar(c);
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
  
          public String next() {
              return String();
          }
  
          public interface SpaceCharFilter {
              public boolean isSpaceChar(int ch);
          }
      }
  
      static class OutputWriter {
          private final PrintWriter writer;
  
          public OutputWriter(OutputStream outputStream) {
              writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
          }
  
          public OutputWriter(Writer writer) {
              this.writer = new PrintWriter(writer);
          }
  
          public void print(Object... objects) {
              for (int i = 0; i < objects.length; i++) {
                  if (i != 0)
                      writer.print(' ');
                  writer.print(objects[i]);
              }
          }
  
          public void printLine(Object... objects) {
              print(objects);
              writer.println();
          }
  
          public void close() {
              writer.close();
          }
  
          public void flush() {
              writer.flush();
          }
      }
  
      static InputReader in = new InputReader(System.in);
      static OutputWriter out = new OutputWriter(System.out);
     
  
      public static int[] sort(int[] a) {
          int n = a.length;
          ArrayList<Integer> l = new ArrayList<>();
          for (int i : a)
              l.add(i);
          Collections.sort(l);
          for (int i = 0; i < l.size(); i++)
              a[i] = l.get(i);
          return a;
      }
      public static long[] sort(long[] a) {
          int n = a.length;
          ArrayList<Long> l = new ArrayList<>();
          for (long i : a)
              l.add(i);
          Collections.sort(l);
          for (int i = 0; i < l.size(); i++)
              a[i] = l.get(i);
          return a;
      }
  
      public static long pow(long x, long y) {
          long res = 1;
          while (y > 0) {
              if (y % 2 != 0) {
                  res = (res * x);// % modulus;
                  y--;
  
              }
              x = (x * x);// % modulus;
              y = y / 2;
          }
          return res;
      }
  //GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      public static long gcd(long x, long y) {
          if (x == 0)
              return y%mod;
          else
              return gcd(y % x, x);
      }
      //****************LOWEST COMMON MULTIPLE   *************************************************************************************************************************************
  
      public static long lcm(long x, long y) {
          return (x * (y / gcd(x, y)));
      }
  //INPUT PATTERN******************************************************************************************************************************************************************
      public static int i() {
          return in.Int();
      }
  
      public static long l() {
          String s = in.String();
          return Long.parseLong(s);
      }
  
      public static String s() {
          return in.String();
      }
  
      public static int[] readArray(int n) {
          int A[] = new int[n];
          for (int i = 0; i < n; i++) {
              A[i] = i();
          }
          return A;
      }
  
      public static long[] readArray(long n) {
          long A[] = new long[(int) n];
          for (int i = 0; i < n; i++) {
              A[i] = l();
          }
          return A;
      }
      public int[][] deepCopy(int[][] matrix) {
  		return java.util.Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone());
  		}
   
  
  }
  
  
  
  
  
  
  	