#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b, c;
  cin >> a >> b >> c;
  long long x[] = {a - 1, a, a + 1};
  long long y[] = {b - 1, b, b + 1};
  long long z[] = {c - 1, c, c + 1};
  long long ans = LONG_MAX;
  for (long long i = 0; i < 3; i++) {
    for (long long j = 0; j < 3; j++) {
      for (long long k = 0; k < 3; k++) {
        long long d = abs(x[i] - y[j]) + abs(y[j] - z[k]) + abs(x[i] - z[k]);
        ans = min(ans, d);
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
