#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1000000007;
const int MAX = 10000005;
const double PI = acos(-1.0);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long a[3];
    for (long long i = 0; i < 3; i++) {
      cin >> a[i];
    }
    sort(a, a + 3);
    if (abs(a[0] - a[2]) <= 1)
      cout << 0;
    else {
      cout << 2 * (a[2] - a[0] - 2);
    }
    cout << "\n";
  }
  return 0;
}
