#include <bits/stdc++.h>
using namespace std;
long long int xo(long long int x, long long int y) {
  return (x | y) & (~x | ~y);
}
long long int bin_Expo(long long int x, long long int n) {
  if (x == 0) return 0;
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return bin_Expo(x * x, n / 2);
  else
    return x * bin_Expo(x * x, (n - 1) / 2);
}
long long int mod_Expo(long long int x, long long int n, long long int M) {
  if (x == 0) return 0;
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return mod_Expo((x * x) % M, n / 2, M);
  else
    return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;
}
bool prime_check(long long int x) {
  bool prime = (x >= 2);
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      prime = false;
      break;
    }
  }
  return prime;
}
long long int logg(long long int base, long long int x) {
  return (long long int)(log(x) / log(base));
}
string s;
map<long long int, set<char> > mm;
void build(long long int node, long long int start, long long int end) {
  if (start == end) {
    mm[node].insert(s[start - 1]);
  } else {
    long long int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    for (__typeof(mm[2 * node].begin()) it = mm[2 * node].begin();
         it != mm[2 * node].end(); it++)
      mm[node].insert(*it);
    for (__typeof(mm[2 * node + 1].begin()) it = mm[2 * node + 1].begin();
         it != mm[2 * node + 1].end(); it++)
      mm[node].insert(*it);
  }
}
void update(long long int node, long long int start, long long int end,
            long long int idx, char val) {
  if (start == end) {
    mm[node].erase(s[idx - 1]);
    mm[node].insert(val);
    s[idx - 1] = val;
  } else {
    long long int mid = (start + end) / 2;
    if (start <= idx && idx <= mid) {
      update(2 * node, start, mid, idx, val);
    } else {
      update(2 * node + 1, mid + 1, end, idx, val);
    }
    for (__typeof(mm[2 * node].begin()) it = mm[2 * node].begin();
         it != mm[2 * node].end(); it++)
      mm[node].insert(*it);
    for (__typeof(mm[2 * node + 1].begin()) it = mm[2 * node + 1].begin();
         it != mm[2 * node + 1].end(); it++)
      mm[node].insert(*it);
  }
}
set<char> query(long long int node, long long int start, long long int end,
                long long int l, long long int r) {
  if (r < start || end < l) {
    set<char> ee;
    ee.clear();
    return ee;
  }
  if (l <= start && end <= r) {
    return mm[node];
  }
  long long int mid = (start + end) / 2;
  set<char> p1 = query(2 * node, start, mid, l, r);
  set<char> p2 = query(2 * node + 1, mid + 1, end, l, r);
  for (__typeof(p2.begin()) it = p2.begin(); it != p2.end(); it++)
    p1.insert(*it);
  return p1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    long long int n, k, i, j, l, m, h, w, q, y;
    y = 300000000007;
    long long int a[3], b[3], c[3], x[3];
    for (long long int i = 0; i < 3; i++) cin >> x[i];
    a[0] = x[0];
    a[1] = x[0] + 1;
    a[2] = x[0] - 1;
    b[0] = x[1];
    b[1] = x[1] + 1;
    b[2] = x[1] - 1;
    c[0] = x[2];
    c[1] = x[2] + 1;
    c[2] = x[2] - 1;
    for (long long int i = 0; i < 3; i++) {
      for (long long int j = 0; j < 3; j++) {
        for (long long int k = 0; k < 3; k++) {
          y = min(y, abs(a[i] - b[j]) + abs(a[i] - c[k]) + abs(b[j] - c[k]));
        }
      }
    }
    cout << y << '\n';
  }
  return 0;
}
