#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, a, b, c, d, e, f, i, j, k = 0, x, y, z, l;
  cin >> t;
  while (t--) {
    long long int ara[5];
    for (l = 0; l < 3; l++) {
      cin >> ara[l];
    }
    sort(ara, ara + 3);
    if (ara[0] == ara[1] == ara[2]) {
      cout << "0" << endl;
    } else if (ara[0] == ara[1]) {
      ara[2] = ara[2] - 1;
      ara[0] = ara[0] + 1;
      ara[1] = ara[1] + 1;
      if (ara[1] < ara[2]) {
        x = ara[2] - ara[0] + ara[2] - ara[1] + ara[1] - ara[0];
        cout << x << endl;
      } else
        cout << "0" << endl;
    } else if (ara[1] == ara[2]) {
      ara[0] = ara[0] + 1;
      ara[1] = ara[1] - 1;
      ara[2] = ara[2] - 1;
      if (ara[0] < ara[1]) {
        x = ara[2] - ara[0] + ara[1] - ara[0];
        cout << x << endl;
      } else
        cout << "0" << endl;
    } else {
      ara[0] = ara[0] + 1;
      ara[1] = ara[1] + 1;
      ara[2] = ara[2] - 1;
      x = ara[2] - ara[0] + ara[2] - ara[1] + ara[1] - ara[0];
      cout << x << endl;
    }
  }
}
