#include <bits/stdc++.h>
void scan(int* i) {
  int t = 0;
  char c;
  bool negative = false;
  c = getchar_unlocked();
  while (c < '0' || c > '9') {
    if (c == '-') negative = true;
    c = getchar_unlocked();
  }
  while (c >= '0' && c <= '9') {
    t = (t << 3) + (t << 1) + c - '0';
    c = getchar_unlocked();
  }
  if (negative) t = ~(t - 1);
  *i = t;
}
void scan(long long int* i) {
  long long int t = 0;
  char c;
  bool negative = false;
  c = getchar_unlocked();
  while (c < '0' || c > '9') {
    if (c == '-') negative = true;
    c = getchar_unlocked();
  }
  while (c >= '0' && c <= '9') {
    t = (t << 3) + (t << 1) + c - '0';
    c = getchar_unlocked();
  }
  if (negative) t = ~(t - 1);
  *i = t;
}
using namespace std;
int main(int argc, char const* argv[]) {
  int n;
  scan(&n);
  for (int z = 0; z < n; z++) {
    int a, b, c;
    int x = 2 * (int)1e9;
    scan(&a);
    scan(&b);
    scan(&c);
    for (int i = -1; i < 2; i++) {
      for (int j = -1; j < 2; j++) {
        for (int k = -1; k < 2; k++) {
          int a1 = a + i;
          int b1 = b + j;
          int c1 = c + k;
          int d = abs(a1 - b1) + abs(a1 - c1) + abs(b1 - c1);
          x = ((x) < (d) ? (x) : (d));
        }
      }
    }
    cout << x << endl;
  }
}
