#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    if (b > c) {
      swap(b, c);
    }
    if (a > b) {
      swap(a, b);
    }
    if (b > c) {
      swap(b, c);
    }
    if (abs(a - b) >= 1 && abs(b - c) >= 1) {
      cout << 2 * abs(c - a) - 4 << endl;
    } else if (abs(a - b) == 0) {
      if (abs(b - c) >= 2) {
        cout << 2 * (abs(b - c) - 2) << endl;
      } else {
        cout << 0 << endl;
      }
    } else if (abs(b - c) == 0) {
      if (abs(a - b) >= 2) {
        cout << 2 * (abs(a - b) - 2) << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
}
