#include <bits/stdc++.h>
int main() {
  int n;
  unsigned long long int t, a, b, c, ans;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> a >> b >> c;
    if (a > b) t = a, a = b, b = t;
    if (b > c) t = b, b = c, c = t;
    if (a > b) t = a, a = b, b = t;
    if (a >= b - 1) {
      if (b >= c - 1) {
        ans = 0;
      } else {
        ans = 2 * (c - 2 - a);
      }
    } else if (b >= c - 1) {
      ans = 2 * (c - 2 - a);
    } else {
      ans = 2 * (c - a - 2);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
