#include using namespace std; void solve(){ int a,b,c;cin>>a>>b>>c; if(a==b && b==c){ if(a >= 3)cout << 3 << endl; else cout << -1 << endl; }else if(a==c){ if(a-1 == b){ if(b==1){ cout << -1 << endl; }else{ cout << 2 << endl; } }else{ cout << 1 << endl; } }else if(a==b){ if(a>c){ if(a-1==c){ if(c==1){ cout << -1 << endl; }else{ cout << 2 << endl; } }else{ cout << 1 << endl; } }else{ if(a==1){ cout << -1 << endl; }else{ cout << 1 << endl; } } }else if(b==c){ if(ab && bc)){ cout << 0 << endl; }else{ if(a>b)swap(a,c); int ans = -1; if(b-a == 1){ if(a!=1){ ans = c-a+1; } }else{ ans = c-b+1; } if(a!=1){ if(ans!=-1){ ans = min(ans,b-a+1); }else{ ans = b-a+1; } } cout << ans << endl; } } } int main(){ int n;cin>>n; for(int i = 0; n > i; i++){ solve(); } }