#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, c;
    cin >> a >> b >> c;
    long long max1 = max(a, max(b, c));
    long long max3 = min(a, min(b, c));
    long long max2 = a + b + c - (max1 + max3);
    if (a != b && b != c && c != a) {
      cout << 2 * (max1 - max3) - 4 << endl;
    } else if (a == b && b == c && c == a) {
      cout << 0 << endl;
    } else {
      if (max1 - max3 == 1) {
        cout << 0 << endl;
      } else {
        cout << 2 * (max1 - max3 - 2) << endl;
      }
    }
  }
}
