#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int arr[3];
    long int ans, res, xs;
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr, arr + 3);
    if (arr[0] == arr[1] && arr[1] != arr[2]) {
      if (arr[2] - arr[1] == 1)
        arr[2]--;
      else if (arr[2] - arr[1] >= 2) {
        arr[0]++;
        arr[1]++;
        arr[2]--;
      }
      res = abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2]);
      cout << res << endl;
    } else if (arr[1] == arr[2] && arr[1] != arr[0]) {
      if (arr[1] - arr[0] == 1)
        arr[0]++;
      else if (arr[1] - arr[0] >= 2) {
        arr[0]++;
        arr[1]--;
        arr[2]--;
      }
      res = abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2]);
      cout << res << endl;
    } else if (arr[0] != arr[1] && arr[1] != arr[2]) {
      arr[0]++;
      arr[2]--;
      res = abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2]);
      arr[1]--;
      ans = abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2]);
      arr[1] += 2;
      xs = abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]) + abs(arr[0] - arr[2]);
      res = min(res, ans);
      res = min(res, xs);
      cout << res << endl;
    } else
      cout << 0 << endl;
  }
  return 0;
}
