#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <set>
using namespace std;

typedef pair<double,double> point;

int main() {
  int T;
  scanf("%d",&T); 
  while (T--) {
    int Ax, Ay, Bx, By;
    double P, Q, R;
    scanf("%d%d%d%d%lf%lf%lf", &Ax, &Ay, &Bx, &By, &P, &Q, &R );

    double result = abs(Ax - Bx) + abs(Ay - By); // not using the Broadway

    // generate all necessary intersections on the Broadway
    vector< point > Z;
    for (int x=min(Ax,Bx)-5; x<=max(Ax,Bx)+5; ++x) Z.push_back( point(x*1., (R - P*x) / Q) );
    for (int y=min(Ay,By)-5; y<=max(Ay,By)+5; ++y) Z.push_back( point((R - Q*y) / P, y*1.) );
    int N = Z.size();
    sort(Z.begin(),Z.end());
    
    // initialize all distances to Manhattan distances
    vector<double> D(N);
    for (int i=0; i<N; ++i) D[i] = abs(Ax-Z[i].first) + abs(Ay-Z[i].second);

    // run Dijkstra's algorithm
    set< pair<double,int> > QQ;
    for (int i=0; i<N; ++i) QQ.insert( make_pair(D[i],i) );
    while (!QQ.empty()) {
      int current = QQ.begin()->second;
      double cur_dist = QQ.begin()->first;
      QQ.erase( QQ.begin() );

      for (int move=-1; move<=1; move+=2) {
        int next = current + move;
        double next_dist = cur_dist + hypot( Z[current].first-Z[next].first, Z[current].second-Z[next].second );
        if (next_dist < D[next] - 1e-9) {
          QQ.erase( make_pair( D[next], next ) );
          D[next] = next_dist;
          QQ.insert( make_pair( D[next], next ) );
        }
      }
    }

    // for each i, compare the best solution so far with the path A -- Z[i] -- B
    for (int i=0; i<N; ++i) result = min( result, D[i] + abs(Bx-Z[i].first) + abs(By-Z[i].second) );

    // output the best solution found
    printf("%.12f\n",result);
  }
}
