#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int a, b, c, ans = 0;
    cin >> a >> b >> c;
    int maxi = max(c, max(a, b));
    int mini = min(c, min(a, b));
    if (a != maxi && a != mini) b = a;
    if (c != maxi && c != mini) b = a;
    a = mini;
    c = maxi;
    a++;
    c--;
    if ((b - a) > (c - b))
      b--;
    else if ((b - a) < (c - b))
      b++;
    if (a < b) ans += b - a;
    if (b < c) ans += c - b;
    if (a < c) ans += c - a;
    cout << ans << "\n";
  }
}
