#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  while (n--) {
    long long arr[3];
    for (int i = 0; i < 3; i++) cin >> arr[i];
    sort(arr, arr + 3);
    if (arr[2] > arr[0]) arr[2]--;
    if (arr[2] > arr[0]) arr[0]++;
    cout << (arr[2] - arr[0]) * 2 << '\n';
  }
}
