#include <bits/stdc++.h>
const int minINF = 1e5;
const int INF = 1e9;
const long long INFL = 1e18;
const int MAX = 1e5 + 100;
const double EPS = 1e-7;
const int MODLE = 1000000007;
bool prime(int n) {
  if (n <= 1) return false;
  if (n == 2) return true;
  for (int x = 2; x * x <= n; x++) {
    if (n % x == 0) return false;
  }
  return true;
}
using namespace std;
int xdir[] = {-1, 1, 0, 0};
int ydir[] = {0, 0, -1, 1};
int v(int a, int b, int c) { return abs(a - b) + abs(b - c) + abs(a - c); }
int main() {
  int q;
  cin >> q;
  while (q--) {
    int a, b, c;
    cin >> a >> b >> c;
    int mine = v(a, b, c);
    for (int k = -1; k < 2; k++) {
      int a1 = a + k;
      mine = min(mine, v(a1, b, c));
      for (int i = -1; i < 2; i++) {
        int b1 = b + i;
        mine = min(mine, v(a1, b1, c));
        for (int j = -1; j < 2; j++) {
          int c1 = c + j;
          mine = min(mine, v(a1, b1, c1));
        }
      }
    }
    cout << mine << "\n";
  }
}
