#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    long long int a, b, c, min1 = 10000000000000, sum;
    cin >> a >> b >> c;
    for (int i = a - 1; i <= a + 1; i++) {
      for (int j = b - 1; j <= b + 1; j++) {
        for (int k = c - 1; k <= c + 1; k++) {
          sum = abs(i - j) + abs(i - k) + abs(j - k);
          min1 = min(sum, min1);
        }
      }
    }
    cout << min1 << "\n";
  }
}
