#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 5;
const long long MAX_N = 1e5 + 5;
const long long MODD = 1e9 + 7;
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }
double min(double a, double b) { return a < b ? a : b; }
long long modd(long long a) {
  if (a < 0LL) return a * -1LL;
  return a;
}
double modd(double a) {
  if (a < 0.0) return a * -1.0;
  return a;
}
long long modulo(long long a) { return (a + MODD) % MODD; }
long long power(long long k, long long p) {
  if (p == 0) return 1LL;
  long long P = power(k, p / 2LL);
  P = (P * P) % MODD;
  if (p % 2 == 1) P = (P * k) % MODD;
  return P;
}
struct p_str {
  long long a, b;
};
void solve() {
  long long v[3];
  for (long long i = 0; i < 3; i++) {
    cin >> v[i];
  }
  sort(v, v + 3);
  long long ans = INF;
  for (long long i = v[0] - 1; i <= v[0] + 1; i++) {
    for (long long j = v[1] - 1; j <= v[1] + 1; j++) {
      for (long long k = v[2] - 1; k <= v[2] + 1; k++) {
        if (i <= j && j <= k) {
          long long t = j - i;
          t += k - j;
          t += k - i;
          ans = min(ans, t);
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
