#include <bits/stdc++.h>
const int mx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
using namespace std;
vector<long long int> v = {0, -1, 1};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  scanf("%d", &q);
  while (q--) {
    long long int ans = INT_MAX;
    long long int a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    for (auto i : v) {
      for (auto j : v) {
        for (auto k : v) {
          ans = min(ans, abs((a + i) - (b + j)) + abs((a + i) - (c + k)) +
                             abs((b + j) - (c + k)));
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
