#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int a, b, c;
  long long int A[2];
  cin >> a >> b >> c;
  A[0] = a;
  A[1] = b;
  A[2] = c;
  sort(A, A + 3);
  a = A[0];
  b = A[1];
  c = A[2];
  if (a != b && b != c && a != c) {
    a++;
    c--;
    cout << abs(b - a) + abs(c - b) + abs(c - a) << endl;
  } else if (a == b && b == c && a == c) {
    cout << 0 << endl;
  } else if (a == b && b != c) {
    c--;
    if (a == b && b == c && a == c) {
      cout << 0 << endl;
    } else {
      a++;
      b++;
      cout << abs(b - a) + abs(c - b) + abs(c - a) << endl;
    }
  } else {
    a++;
    if (a == b && b == c && a == c) {
      cout << 0 << endl;
    } else {
      b--;
      c--;
      cout << abs(b - a) + abs(c - b) + abs(c - a) << endl;
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
