#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q;
  cin >> q;
  while (q--) {
    vector<long long> a(3);
    for (long long i = 0; i < 3; i++) cin >> a[i];
    sort(a.begin(), a.end());
    cout << max(0 * 1ll,
                abs(a[0] - a[2]) + abs(a[0] - a[1]) + abs(a[2] - a[1]) - 4)
         << "\n";
  }
}
