#include <bits/stdc++.h>
using namespace std;

typedef long double ld;
typedef complex<ld> p;
const ld EPS = 1e-5;
#define M 10000

p a, b, c, d;
p clo, chi, dlo, dhi;

ld dd(const p& c, const p& d) {
  return abs(a - b) + abs(c - d) + min(abs(b - d) + abs(c - a), abs(a - d) + abs(c - b));
}

ld dc(const p &c) {
  dlo = p(0, 0);
  dhi = p(M, 0);
  p dm1;
  p dm2;
  while (abs(dhi - dlo) > EPS) {
    dm1 = dlo + (dhi - dlo) / (ld) 3;
    dm2 = dlo + (dhi - dlo) / (ld) 3 * (ld) 2;
    if (dd(c, dm1) < dd(c, dm2)) {
      dhi = dm2;
    } else {
      dlo = dm1;
    }
  }
  return dd(c, dlo);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  while (n--) {
    ld ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;
    a = p(ax, ay);
    b = p(bx, by);
    c = p(0, M);
    d = p(M, 0);

    clo = p(0, 0);
    chi = p(0, M);
    p cm1;
    p cm2; 
    while (abs(chi - clo) > EPS) {
      cm1 = clo + (chi - clo) / (ld) 3;
      cm2 = clo + (chi - clo) / (ld) 3 * (ld) 2; 
      if (dc(cm1) < dc(cm2)) {
        chi = cm2;
      } else {
        clo = cm1;
      }
    }
    cout << fixed << setprecision(3) << dc(clo) << endl;
  }
  return 0;
}