#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<long long int> Mas(3);
    long long int res = 0;
    cin >> Mas[0] >> Mas[1] >> Mas[2];
    sort(Mas.begin(), Mas.end());
    if (Mas[0] == Mas[1] && Mas[0] < Mas[2]) {
      Mas[0]++;
      Mas[1]++;
    } else if (Mas[1] == Mas[2] && Mas[2] > Mas[0]) {
      Mas[1]--;
      Mas[2]--;
    }
    if (Mas[0] < Mas[1]) Mas[0]++;
    if (Mas[2] > Mas[1]) Mas[2]--;
    res = abs(Mas[0] - Mas[1]) + abs(Mas[0] - Mas[2]) + abs(Mas[1] - Mas[2]);
    cout << res << endl;
  }
  return 0;
}
