#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    int a[3];
    for (int i = 0; i < 3; i++) {
      cin >> a[i];
    }
    sort(a, a + 3);
    long c;
    if (a[0] == a[1] && a[1] == a[2])
      c = 0;
    else if (a[0] == a[1] && a[2] - a[0] > 1) {
      c = (a[2] - 1) * 2 - (a[0] + a[1] + 2);
    } else if (a[0] == a[1] && a[2] - a[0] == 1) {
      c = 0;
    } else if (a[1] == a[2] && a[2] - a[0] > 1) {
      c = (a[1] + a[2] - 2) - (a[0] + 1) * 2;
    } else if (a[1] == a[2] && a[2] - a[0] == 1) {
      c = 0;
    } else {
      c = a[1] - a[0] - 1 + a[2] - 1 - a[1] + a[2] - a[0] - 2;
    }
    cout << c << "\n";
    t--;
  }
}
