#include <bits/stdc++.h>
using namespace std;
void solve() {
  vector<int> pos(3);
  for (int i = 0; i < 3; i++) cin >> pos[i];
  sort(pos.begin(), pos.end());
  if (pos[0] != pos[2] && pos[0] != pos[1] && pos[1] != pos[2]) {
    pos[0]++;
    pos[2]--;
    cout << max(0, 2 * pos[2] - 2 * pos[0]) << endl;
    return;
  }
  if ((pos[0] == pos[1] && pos[0] != pos[2]) ||
      (pos[1] == pos[2] && pos[0] != pos[2])) {
    cout << max(0, 2 * pos[2] - 2 * pos[0] - 4) << endl;
    return;
  }
  cout << "0" << endl;
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
