#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 3333;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << max(0, (a[2] - a[0] - 2) * 2) << endl;
  }
}
