#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    cin >> a >> b >> c;
    int mn = abs(a - b) + abs(a - c) + abs(b - c);
    for (int i = a - 1; i <= a + 1; i++) {
      for (int k = b - 1; k <= b + 1; k++) {
        for (int j = c - 1; j <= c + 1; j++) {
          mn = min(mn, abs(i - k) + abs(i - j) + abs(k - j));
        }
      }
    }
    cout << mn << '\n';
  }
}
