#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int i1 = 0; i1 < q; i1++) {
    vector<long long> v;
    for (int i = 0; i < 3; i++) {
      long long a;
      cin >> a;
      v.push_back(a);
    }
    sort(v.begin(), v.end());
    if (v[0] == v[2]) {
      cout << 0 << endl;
      continue;
    }
    if (abs(v[0] - v[2]) == 1) {
      cout << 0 << endl;
      continue;
    }
    v[0] += 1;
    v[2] -= 1;
    cout << (2 * (v[2] - v[0])) << endl;
  }
}
