#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> va, vb, vc;
    va.push_back(a);
    va.push_back(a + 1);
    va.push_back(a - 1);
    vb.push_back(b);
    vb.push_back(b + 1);
    vb.push_back(b - 1);
    vc.push_back(c);
    vc.push_back(c + 1);
    vc.push_back(c - 1);
    int ans = INT_MAX;
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++)
        for (int k = 0; k < 3; k++)
          ans = min(ans, abs(va[i] - vb[j]) + abs(va[i] - vc[k]) +
                             abs(vb[j] - vc[k]));
    cout << ans << "\n";
  }
  return 0;
}
