#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int x[3];
    cin >> x[0] >> x[1] >> x[2];
    sort(x, x + 3);
    if (x[0] == x[1] && x[0] == x[2]) {
      cout << 0 << endl;
      continue;
    }
    if (x[0] == x[1]) {
      x[0]++;
      x[1]++;
    }
    if (x[0] == x[1] && x[0] == x[2]) {
      cout << 0 << endl;
      continue;
    }
    if (x[02] == x[1]) {
      x[2]--;
      x[1]--;
    }
    if (x[0] == x[1] && x[0] == x[2]) {
      cout << 0 << endl;
      continue;
    }
    if (x[0] < x[1]) x[0]++;
    if (x[2] > x[1]) x[2]--;
    cout << abs(x[0] - x[1]) + abs(x[0] - x[2]) + abs(x[1] - x[2]) << endl;
  }
  return 0;
}
