#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, num[3];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[0] >> num[1] >> num[2];
    sort(num, num + 3);
    if (num[2] > num[0] + 1) {
      num[2]--;
      num[0]++;
    } else if (num[2] == num[0] + 1)
      num[2]--;
    cout << 2 * (num[2] - num[0]) << endl;
  }
  return 0;
}
