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