#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
vector<int> volume(1000000);
vector<int> parent(1000000);
void initialise_dsu() {
  for (int i = 0; i < volume.size(); i++) volume[i] = 1;
  for (int i = 0; i < parent.size(); i++) parent[i] = i;
}
int find_par(int v) {
  return (v == parent[v] ? v : parent[v] = find_par(parent[v]));
}
void union_sets(int a, int b) {
  a = find_par(a);
  b = find_par(b);
  if (a != b) {
    if (volume[a] < volume[b]) swap(a, b);
    parent[b] = a;
    volume[a] += volume[b];
  }
}
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  while (n--) {
    long int a, b, c;
    cin >> a >> b >> c;
    long ans = abs(a - b) + abs(b - c) + abs(c - a);
    vector<int> lop;
    for (long i = a - 1; i <= a + 1; i++)
      for (long j = b - 1; j <= b + 1; j++)
        for (long k = c - 1; k <= c + 1; k++)
          ans = min(ans, abs(i - j) + abs(j - k) + abs(k - i));
    cout << ans << endl;
  }
}
