#include <bits/stdc++.h>
using namespace std;
const long long LLOO = 1e18 + 7;
const int OO = 1e9 + 7;
const int MOD = 1e9 + 9;
const int N = 1e5 + 7;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    long long a, b, c;
    scanf("%lld %lld %lld", &a, &b, &c);
    long long ans = LLOO;
    for (int i = -1; i <= (1); ++i)
      for (int j = -1; j <= (1); ++j)
        for (int k = -1; k <= (1); ++k) {
          long long aa = a + i;
          long long bb = b + j;
          long long cc = c + k;
          long long res = abs(aa - bb) + abs(aa - cc) + abs(bb - cc);
          ans = min(ans, res);
        }
    printf("%lld\n", ans);
  }
  return 0;
}
