#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  int a[3];
  cin >> t;
  while (t--) {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    int ans = 2 * (a[2] - a[0] - 2);
    cout << max(0, ans) << "\n";
  }
}
