#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    cin >> a >> b >> c;
    int c1 = max(a, max(b, c));
    int b1;
    int a1 = min(a, min(b, c));
    if ((a < b && b < c) || (c < b && b < a))
      b1 = b;
    else if ((b < a && a < c) || (c < a && a < b))
      b1 = a;
    else
      b1 = c;
    a = a1;
    b = b1;
    c = c1;
    if (a == b && b == c)
      cout << 0 << '\n';
    else {
      if (a == b) {
        c = c - 1;
        if (a != c) {
          a++;
          b++;
        }
      } else if (b == c) {
        a = a + 1;
        if (b != a) {
          b--;
          c--;
        }
      } else {
        a = a + 1;
        c = c - 1;
        if (a != b)
          b = b - 1;
        else {
          if (b != c) b++;
        }
      }
      cout << abs(a - b) + abs(b - c) + abs(c - a) << '\n';
      ;
    }
  }
}
