#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long q;
  cin >> q;
  while (q--) {
    long long a, b, c;
    cin >> a >> b >> c;
    long long ans = 1000000000000;
    for (long long i = -1; i < 2; i++) {
      for (long long j = -1; j < 2; j++) {
        for (long long k = -1; k < 2; k++) {
          long long temp =
              abs(a + i - b - j) + abs(a + i - c - k) + abs(b + j - c - k);
          ans = min(ans, temp);
        }
      }
    }
    cout << ans << "\n";
  }
}
