#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int a[4];
    for (int i = 0; i < (3); i++) cin >> a[i];
    sort(a, a + 3);
    if (a[0] == a[1] && a[1] == a[2])
      cout << 0 << endl;
    else {
      cout << max(2 * (a[2] - a[0] - 2), 0) << endl;
    }
  }
  return 0;
}
