/*
ALLAH IS THE GREATEST
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl "\n"
const ll Mod = 2e18+7;
const ll N = 1e5+7;
#define Subhanallah_Alhamdulillah_Allahu_Akbar ios_base::sync_with_stdio(false);cin.tie(NULL);
bool bs[10000007];
const ll sz = 1e6+5;
typedef pair<ll,ll>pi;
vector<ll>prime;
ll vis[N];
ll arr[N];
vector<ll>graph[N];
void sieve()
{
bs[0]=bs[1]=1;
for(ll i=3;i*i<=sz;i+=2)
{
if(!bs[i])
{
for(ll j=i*i;j<=sz;j+=i)
{
bs[j]=1;
}
}
}
prime.push_back(2);
for(ll i=3;i<=sz;i+=2)
{
if(!bs[i])
{
prime.push_back(i);
}
}
sort(prime.rbegin(),prime.rend());
}
ll mod(ll a, ll m){
return (a % m + m) % m;
}
ll biexpo(ll base,ll power)
{
ll ans =1;
while(power)
{
if(power%2==1)
{
ans=(ans*base);
power--;
}
else
{
base=(base*base);
power/=2;
}
}
return ans;
}
ll dfs(ll n)
{
vector<ll>v;
vis[n]=1;
stack<ll>st;
st.push(n);
while(!st.empty())
{
ll cur = st.top();
v.push_back(cur);
st.pop();
for(auto &i:graph[cur])
{
if(!vis[i])
{
st.push(i);
vis[i]=1;
}
}
}
ll mi = 1e18;
for(auto &k:v)
{
mi = min(mi,arr[k-1]);
}
return mi;
}
ll digsum(ll a)
{
ll sum=0;
while(a)
{
sum+=(a%10);
a/=10;
}
return sum;
}
int main()
{
//Think positively and move on
ll t;
cin>>t;
while(t--)
{
ll a,b,c;
cin>>a>>b>>c;
if(a==b && b==c)
{
cout<<0<<nl;
continue;
}
vector<ll>v,u;
v.push_back(a);
v.push_back(b);
v.push_back(c);
map<ll,ll>mp;
for(ll i=0;i<v.size();i++)
{
mp[v[i]]++;
}
ll mx = INT_MIN;
for(ll i=0;i<3;i++)
{
mx = max(mp[v[i]],mx);
}
if(mx==2)
{
cout<<1<<nl;
continue;
}
for(ll i=0;i<v.size();i++)
{
for(ll j=1;j*j<=v[i];j++)
{
if(v[i]%j==0)
{
u.push_back(j);
if(j!=(v[i]/j))
{
u.push_back(v[i]/j);
}
}
}
}
ll sk;
map<ll,ll>dp;
for(ll i=0;i<u.size();i++)
{
dp[u[i]]++;
}
for(auto &k:dp)
{
if(k.second==3)
{
sk=k.first;
}
}
sort(v.begin(),v.end());
ll uk = v[2]-v[0]+v[2]-v[1];
ll ans= uk/sk;
ll rk = v[1]-v[0]+v[2]-v[1];
ll ans1 = rk/sk;
ll mk = v[1]-v[0]+v[2]-v[0];
ll ans2= mk/sk;
ll res = min(ans,ans1);
cout<<min(ans2,res)<<nl;
}
return 0;
}