#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, a, b, c;
  scanf("%d", &n);
  while (n--) {
    int s[5] = {0};
    scanf("%d%d%d", &s[0], &s[1], &s[2]);
    sort(s, s + 3);
    if (s[0] == s[2])
      printf("0\n");
    else if (s[0] == s[1]) {
      if (s[2] - s[1] == 1)
        printf("0\n");
      else
        printf("%d\n", (s[2] - s[1] - 2) * 2);
    } else if (s[1] == s[2])
      if (s[1] - s[0] == 1)
        printf("0\n");
      else
        printf("%d\n", (s[1] - s[0] - 2) * 2);
    else
      printf("%d\n", s[2] - s[1] + s[1] - s[0] + s[2] - s[0] - 4);
  }
  return 0;
}
