#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  for (long long i = 1; i <= t; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    if (abs(a - b) <= 2 && abs(a - c) <= 2 && abs(b - c) <= 2)
      cout << 0 << "\n";
    else if (abs(a - b) > 2 || abs(a - c) > 2 || abs(b - c) > 2)
      cout << abs(a - b) + abs(a - c) + abs(b - c) - 4 << "\n";
  }
  return 0;
}
