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