#include <bits/stdc++.h>
long long int power(long long int x, long long int b) {
  long long int p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= 1000000007;
    }
    b >>= 1;
    x *= x;
    x %= 1000000007;
  }
  return p % 1000000007;
}
using namespace std;
bool func(string s1, string s2, long long int n) {
  long long int index1 = -1, index2 = -1;
  for (long long int i = 0; i < n; i++) {
    if (s1[i] != s2[i]) {
      if (index1 == -1) {
        index1 = i;
      } else if (index2 == -1) {
        index2 = i;
      } else {
        return false;
      }
    }
  }
  if (index2 == -1) {
    return false;
  }
  if (s1[index1] == s1[index2] && s2[index1] == s2[index2]) {
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int q;
  cin >> q;
  while (q--) {
    long long int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (abs(a[0] - a[1]) <= 1 && abs(a[2] - a[1]) <= 1) {
      cout << 0 << "\n";
      continue;
    }
    if (a[0] != a[1] && a[1] != a[2]) {
      a[0]++, a[2]--;
      cout << a[1] - a[0] + a[2] - a[1] + a[2] - a[0] << "\n";
      continue;
    }
    if (a[0] == a[1]) {
      a[2]--;
      a[1]++;
      cout << 2 * (a[2] - a[1]) << "\n";
      continue;
    }
    if (a[1] == a[2]) {
      a[1]--;
      a[0]++;
      cout << 2 * (a[1] - a[0]) << "\n";
      continue;
    }
  }
  return 0;
}
