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