#include <bits/stdc++.h>
using namespace std;
int q;
int main() {
  cin >> q;
  while (q--) {
    int aa, ab, ac, a, b, c, r = INT_MAX;
    cin >> aa >> ab >> ac;
    a = min(min(aa, ab), ac);
    c = max(max(aa, ab), ac);
    b = aa + ab + ac - a - c;
    for (int i = -1; i < 2; i++) {
      for (int j = -1; j < 2; j++) {
        for (int k = -1; k < 2; k++) {
          r = min(r, (abs(c + k - a - i) + abs(b + j - a - i) +
                      abs(c + k - b - j)));
        }
      }
    }
    cout << r << endl;
  }
}
