#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    int ans = abs(a[0] - a[1]) + abs(a[0] - a[2]) + abs(a[1] - a[2]);
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        for (int k = -1; k <= 1; k++) {
          int x = a[0] + i;
          int y = a[1] + j;
          int z = a[2] + k;
          ans = min(ans, abs(x - y) + abs(x - z) + abs(y - z));
        }
      }
    }
    cout << ans << endl;
  }
}
