#include <bits/stdc++.h>
using namespace std;
long long cas;
long long a;
long long b;
long long c;
long long d[] = {0, 1, -1};
int main() {
  scanf("%lld", &cas);
  while (cas--) {
    scanf("%lld %lld %lld", &a, &b, &c);
    long long ans = 21413524368453;
    for (long long i = 0; i < 3; ++i) {
      long long aa = a + i;
      for (long long j = 0; j < 3; ++j) {
        long long bb = b + j;
        for (long long k = 0; k < 3; ++k) {
          long long cc = c + k;
          ans = min(ans, abs(aa - bb) + abs(aa - cc) + abs(bb - cc));
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
