#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int ans = 2e9;
    int ta, tb, tc;
    for (int i = -1; i <= 1; i++)
      for (int j = -1; j <= 1; j++)
        for (int k = -1; k <= 1; k++) {
          ta = a + i, tb = b + j, tc = c + k;
          ans = min(ans, abs(ta - tb) + abs(ta - tc) + abs(tb - tc));
        }
    printf("%d\n", ans);
  }
  return 0;
}
