#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max((abs(a - b) + abs(b - c) + abs(c - a) - 4), 0) << endl;
  }
  int sum = 0;
  for (int i = 0; i < 1e9; i++) {
    sum = (sum + 5) % 1868851;
  }
  sum = sum * sum;
  return 0;
}
