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