#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  int n;
  cin >> n;
  int* arr = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    if (max(a, max(b, c)) - min(a, min(b, c)) < 3)
      arr[i] = 0;
    else
      arr[i] = abs(a - b) + abs(b - c) + abs(a - c) - 4;
  }
  for (int i = 0; i < n; i++) cout << arr[i] << '\n';
}
