#include <bits/stdc++.h>
using namespace std;
int diff(int a, int b, int c) {
  int y = abs(a - b) + abs(b - c) + abs(a - c);
  return y;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    vector<int> v;
    for (int i = 0; i < 3; i++) {
      int in;
      cin >> in;
      v.push_back(in);
    }
    sort(v.begin(), v.end());
    int minD;
    if (v[0] == v[1] && v[1] == v[2]) {
      minD = 0;
    } else if (v[0] == v[1] && v[1] != v[2]) {
      int checker = v[2] - v[1];
      if (checker > 1) {
        minD = diff(v[0] + 1, v[1] + 1, v[2] - 1);
      } else {
        minD = diff(v[0], v[1], v[2] - 1);
      }
    } else if (v[0] != v[1] && v[1] == v[2]) {
      int checker = v[1] - v[0];
      if (checker > 1) {
        minD = diff(v[0] + 1, v[1] - 1, v[2] - 1);
      } else {
        minD = diff(v[0] + 1, v[1], v[2]);
      }
    } else {
      minD = diff(v[0] + 1, v[1], v[2] - 1);
    }
    cout << minD << endl;
  }
}
