#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
long long gcd(long long a, long long b) {
  if (a < b)
    return gcd(b, a);
  else if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long isPrime(long long n) {
  long long p = (long long)sqrt(n);
  for (long long i = (2); i <= (p); i += (1))
    if (n % i == 0) return 0;
  return 1;
}
long long powm(long long x, long long y, long long m = 1000000007) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long modInverse(long long a, long long m) { return powm(a, m - 2, m); }
bool issq(long long n) {
  long long p = sqrt(n);
  return p * p == n;
}
long long MIN(long long a = 2e18, long long b = 2e18, long long c = 2e18,
              long long d = 2e18, long long e = 2e18) {
  return min(a, min(b, min(c, min(d, e))));
}
long long MAX(long long a = -2e18, long long b = -2e18, long long c = -2e18,
              long long d = -2e18, long long e = -2e18) {
  return max(a, max(b, max(c, max(d, e))));
}
vector<long long> prime;
void seive(long long n) {
  prime.resize(n + 1);
  for (long long i = (2); i <= (n); i += (1))
    if (prime[i] == 0) {
      prime[i] = i;
      for (long long j = (i * i); j <= (n); j += (i))
        if (prime[j] == 0) prime[j] = i;
    }
}
long long extended_GCD(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
long long mulInv(long long a, long long mod) {
  long long x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0) x += mod;
  return x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<vector<long long> > v;
  for (long long i = -1; i <= 1; i++)
    for (long long j = -1; j <= 1; j++)
      for (long long k = -1; k <= 1; k++) {
        vector<long long> x;
        x.push_back(i);
        x.push_back(j);
        x.push_back(k);
        v.push_back(x);
      }
  long long T;
  cin >> T;
  while (T--) {
    long long ans = 1e17L;
    long long a, b, c;
    cin >> a >> b >> c;
    for (auto x : v) {
      long long p = x[0] + a, q = x[1] + b, r = x[2] + c;
      ans = min(ans, abs(p - q) + abs(q - r) + abs(p - r));
    }
    cout << ans;
    cout << "\n";
  }
  return 0;
}
