#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt = 0, ttt = 0;
  scanf("%d", &tt);
  while (tt--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int p = (1 << 30) - 5 + (1 << 30);
    for (int i = -1; i < 2; i++) {
      for (int j = -1; j < 2; j++) {
        for (int k = -1; k < 2; k++) {
          int u = i + a;
          int v = j + b;
          int w = k + c;
          if (abs(u - v) + abs(w - v) + abs(u - w) < p)
            p = abs(u - v) + abs(w - v) + abs(u - w);
        }
      }
    }
    printf("%d\n", p);
  }
  return 0;
}
