#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c;
    long long z[3];
    for (long long i = 0; i < 3; i++) {
      cin >> z[i];
    }
    sort(z, z + 3);
    a = z[0];
    b = z[1];
    c = z[2];
    vector<long long> v;
    int p = abs(a - b) + abs(b - c) + abs(c - a);
    v.push_back(p);
    int q = abs((a + 1) - (b + 1)) + abs((b + 1) - c) + abs(c - (a + 1));
    v.push_back(q);
    int r = abs((a + 1) - (b - 1)) + abs((b - 1) - (c - 1)) +
            abs((c - 1) - (a + 1));
    v.push_back(r);
    int s = abs((a + 1) - (b)) + abs((b) - (c - 1)) + abs((c - 1) - (a + 1));
    v.push_back(s);
    int t = abs((a + 1) - (b + 1)) + abs((b + 1) - (c - 1)) +
            abs((c - 1) - (a + 1));
    v.push_back(t);
    int u = abs((a + 1) - (b)) + abs((b) - (c)) + abs((c) - (a + 1));
    v.push_back(u);
    long long d = *min_element(v.begin(), v.end());
    cout << d << endl;
  }
  return 0;
}
