#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int f[3];
    cin >> f[0] >> f[1] >> f[2];
    sort(f, f + 3);
    if (f[0] == f[1] && f[1] == f[2]) {
      cout << 0 << endl;
    } else if (f[0] == f[1]) {
      int sub = 2;
      if (f[2] - f[1] != 1) sub += 2;
      cout << (f[2] - f[1]) * 2 - sub << endl;
    } else if (f[1] == f[2]) {
      int sub = 2;
      if (f[1] - f[0] != 1) sub += 2;
      cout << (f[1] - f[0]) * 2 - sub << endl;
    } else
      cout << (f[2] - f[1]) + (f[1] - f[0]) + (f[2] - f[0]) - 4 << endl;
  }
}
