#include <bits/stdc++.h>
using namespace std;
void sieve(long long n, vector<bool> &prime) {
  prime[0] = false;
  prime[1] = false;
  for (long long i = 2; i * i <= n; i++) {
    if (prime[i] == true) {
      for (long long j = i * i; j <= n; j += i) prime[j] = false;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long q;
  cin >> q;
  while (q--) {
    long long a[3], b[3], c[3];
    cin >> a[1];
    cin >> b[1];
    cin >> c[1];
    a[0] = a[1] - 1;
    a[2] = a[1] + 1;
    b[0] = b[1] - 1;
    b[2] = b[1] + 1;
    c[0] = c[1] - 1;
    c[2] = c[1] + 1;
    long long ans = INT_MAX;
    for (long long i = (long long)0; i <= (long long)2; i++) {
      for (long long j = (long long)0; j <= (long long)2; j++) {
        for (long long k = (long long)0; k <= (long long)2; k++) {
          ans =
              min(ans, abs(a[i] - b[j]) + abs(a[i] - c[k]) + abs(b[j] - c[k]));
        }
      }
    }
    cout << ans << endl;
  }
}
