#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a, b, c, x, y, z;
    cin >> a >> b >> c;
    x = min(a, min(b, c));
    y = max(a, max(b, c));
    if (x < b && b < y)
      z = b;
    else if (x < a && a < y)
      z = a;
    else
      z = c;
    int ans = 0, ans1 = 0, ans2 = 0, ans3 = 0;
    ans = (z - (x + 1)) + ((y - 1) - z) + (y - 1) - (x + 1);
    ans1 = (z - x) + ((y - 1) - z) + ((y - 1) - x);
    ans2 = (z - (x + 1)) + ((y)-z) + (y) - (x + 1);
    ans3 = (z - (x)) + ((y)-z) + (y - x);
    ans = min(ans, min(ans1, min(ans2, ans3)));
    if (ans < 0) ans = 0;
    cout << ans << endl;
  }
  return 0;
}
