#include <bits/stdc++.h>
using namespace std;
void fast() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
}
long long numOfDigits(long long n);
long long BN(long long arr[], long long j, long long val);
bool compare(int &a, int &b) { return a > b; }
int main() {
  ;
  fast();
  ;
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c, mn = LLONG_MAX;
    cin >> a >> b >> c;
    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 x = a + i, y = b + j, z = c + k;
          mn = min(mn, abs(x - y) + abs(x - z) + abs(y - z));
        }
    cout << mn << "\n";
    ;
  }
  return 0;
}
long long numOfDigits(long long n) {
  if (!n) return 1;
  return (long long)(log10(n) + 1);
}
