#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;
  x = x - i >= 0.5 ? (x - 1) : (x - i <= -0.5 ? (x + 1) : x);
  y = y - i >= 0.5 ? (y - 1) : (y - i <= -0.5 ? (y + 1) : y);
  z = z - i >= 0.5 ? (z - 1) : (z - i <= -0.5 ? (z + 1) : 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;
}
