#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1000009;
long long t, a, b, c;
long long d[] = {-1, 0, 1};
signed main() {
  cin >> t;
  while (t--) {
    cin >> a >> b >> c;
    long long sum = LLONG_MAX;
    for (long long i = 0; i < 3; i++) {
      for (long long j = 0; j < 3; j++) {
        for (long long k = 0; k < 3; k++) {
          sum =
              min(sum, abs(a + d[i] - (b + d[j])) + abs(b + d[j] - (c + d[k])) +
                           abs(c + d[k] - (a + d[i])));
        }
      }
    }
    cout << sum << endl;
  }
}
