#include <bits/stdc++.h>
using namespace std;
long long a, b, c;
long long min1(long long a, long long b, long long c) {
  return abs(a - b) + abs(a - c) + abs(b - c);
}
void ans() {
  cin >> a >> b >> c;
  long long mi = 1e18;
  for (long long i = -1; i < 2; ++i) {
    for (long long j = -1; j < 2; ++j) {
      for (long long x = -1; x < 2; ++x) {
        mi = min(min1(a + i, b + j, c + x), mi);
      }
    }
  }
  cout << mi << endl;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    ans();
  }
  return 0;
}
