#include <bits/stdc++.h>
using namespace std;
int t, a[3];
void solve() {
  for (int i = 0; i < 3; i++) cin >> a[i];
  sort(a, a + 3);
  int ans = (a[2] - a[0]) * 2;
  int res = min(ans, min(ans - 2, min(ans - 4, min(ans + 2, ans + 4))));
  if (res > 0)
    cout << res << endl;
  else
    cout << 0 << endl;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> t;
  while (t--) {
    solve();
  }
}
