#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    long long ans = 5 * 10e9;
    int a[4];
    cin >> a[1] >> a[2] >> a[3];
    for (long long i = a[1] - 1; i <= a[1] + 1; i++) {
      for (long long j = a[2] - 1; j <= a[2] + 1; j++) {
        for (long long k = a[3] - 1; k <= a[3] + 1; k++)
          ans = min(ans, abs(i - j) + abs(j - k) + abs(i - k));
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
