#include <bits/stdc++.h>
using namespace std;
int main(){
int q;
cin>>q;
vector<int>v(3);
while(q--){
for(auto it:v)
cin>>it;
sort(v.begin(),v.end());
if(v[0]==v[1]&&v[1]==v[2])// 5 5 5
cout<<0<<endl;
else if(v[0]==v[1]&&v[2]-v[1]==1) // 3 3 4
cout<<0<<endl;
else if(v[1]==v[2]&&v[1]-v[0]==1)// 2 3 3
cout<<0<<endl;
else if(v[1]==v[2]) //2 5 5
cout<<(v[1]-v[0]-2)*2<<endl;
else if(v[0]==v[1]) //3 3 6
cout<<(v[2]-v[1]-2)*2<<endl;
else {
cout<<(v[1]-v[0]-1)+(v[2]-v[1]-1)+(v[2]-v[0]-2)<<endl;
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCl7CiAgICBpbnQgcTsKICAgIGNpbj4+cTsKICAgIHZlY3RvcjxpbnQ+digzKTsKICAgIHdoaWxlKHEtLSl7CiAgICAgIGZvcihhdXRvIGl0OnYpCiAgICAgICAgY2luPj5pdDsKICAgICAgc29ydCh2LmJlZ2luKCksdi5lbmQoKSk7CiAgICAgIGlmKHZbMF09PXZbMV0mJnZbMV09PXZbMl0pLy8gNSA1IDUKICAgICAgY291dDw8MDw8ZW5kbDsKICAgICAgZWxzZSBpZih2WzBdPT12WzFdJiZ2WzJdLXZbMV09PTEpIC8vIDMgMyA0CiAgICAgICAgY291dDw8MDw8ZW5kbDsKICAgICAgZWxzZSBpZih2WzFdPT12WzJdJiZ2WzFdLXZbMF09PTEpLy8gMiAzIDMKICAgICAgICBjb3V0PDwwPDxlbmRsOwogICAgICBlbHNlIGlmKHZbMV09PXZbMl0pIC8vMiA1IDUgCiAgICAgICAgIGNvdXQ8PCh2WzFdLXZbMF0tMikqMjw8ZW5kbDsKICAgICAgZWxzZSBpZih2WzBdPT12WzFdKSAgLy8zIDMgNgogICAgICAgICAgY291dDw8KHZbMl0tdlsxXS0yKSoyPDxlbmRsOwogICAgICBlbHNlIHsKICAgICAgICAgIGNvdXQ8PCh2WzFdLXZbMF0tMSkrKHZbMl0tdlsxXS0xKSsodlsyXS12WzBdLTIpPDxlbmRsOwogICAgICB9CiAgICB9Cn0=