#include <bits/stdc++.h>
long long m = 1000000007;
long long sieve[1000001] = {0}, i, j;
long long power(long long p, long long k) {
  long long a = 1;
  while (k) {
    if (k & 1) a = (a * p) % m;
    p = (p * p) % m;
    k >>= 1;
  }
  return a;
}
using namespace std;
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    int a, b, c, ans = 0;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(), v.end());
    if ((v[1] == v[0]) && (v[2] == v[1]))
      ans = 0;
    else {
      if (v[1] == v[0] && (v[2] - v[1]) >= 2)
        ans = 2 * abs(v[2] - v[1] - 2);
      else if (v[2] == v[1] && (v[1] - v[0]) >= 2)
        ans = 2 * abs(v[1] - v[0] - 2);
      else {
        if (v[1] > v[0]) v[0] += 1;
        if (v[2] > v[1]) v[2] -= 1;
        ans += abs(v[1] - v[0]) + abs(v[2] - v[0]) + abs(v[2] - v[1]);
      }
    }
    cout << ans;
    cout << "\n";
  }
}
