#include <bits/stdc++.h>
unsigned long abs(unsigned long x, unsigned long y) {
  if (x > y)
    return (x - y);
  else
    return (y - x);
}
unsigned long ThreeFriends(unsigned long x, unsigned long y, unsigned long z) {
  double i = (double)(x + y + z) / 3;
  if (x - i > 0.5) {
    x = x - 1;
  } else if (x - i <= -0.5) {
    x = x + 1;
  } else {
    x = x;
  }
  if (y - i >= 0.5) {
    y = y - 1;
  } else if (y - i <= -0.5) {
    y = y + 1;
  } else {
    y = y;
  }
  if (z - i >= 0.5) {
    z = z - 1;
  } else if (z - i <= -0.5) {
    z = z + 1;
  } else {
    z = z;
  }
  return (abs(x, y) + abs(x, z) + abs(y, z));
}
int main() {
  int q;
  scanf("%d", &q);
  unsigned long Q[q][3];
  int i;
  for (i = 0; i < q; i++) {
    scanf("%ld %ld %ld", &Q[i][0], &Q[i][1], &Q[i][2]);
  }
  for (i = 0; i < q; i++) {
    int x = ThreeFriends(Q[i][0], Q[i][1], Q[i][2]);
    printf("%ld \n", x);
  }
  return 0;
}
