#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    long long int avg = (a[0] + a[2]) / 2;
    long long int ans = 0;
    for (long long int i = 0; i < 3; i++) {
      if (avg > a[i])
        a[i] += 1;
      else if (avg < a[i])
        a[i] -= 1;
    }
    ans += (abs(a[0] - a[1]) + abs(a[2] - a[1]) + abs(a[0] - a[2]));
    cout << ans << "\n";
  }
  return 0;
}
