#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int temp = 0;
    if (a == b && b == c) {
      printf("0\n");
    } else {
      if (b > a) {
        temp = b;
        b = a;
        a = temp;
      }
      if (c > a) {
        temp = c;
        c = a;
        a = temp;
      }
      if (b >= c) {
        printf("%d\n", max(2 * (a - c) - 4, 0));
      } else {
        printf("%d\n", max(2 * (a - b) - 4, 0));
      }
    }
  }
}
