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