#pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG #include using namespace std; #define int long long template inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; } void num(int n) { cout << n << endl; } int mid(int a, int b,int c) { return a+b+c-min({a,b,c})-max({a,b,c}); } void solve() { int a, b, c; cin >> a >> b >> c; if (a < c) swap(a, c); if (a != b && b != c && c != a) { if (mid(a,b,c)==a||mid(a,b,c)==c) { cout << 0 << endl; return; } if (b == 2 && c == 1) { cout << -1 << endl; return; } int d = abs(a-b)+1; if (b-1==c)d++; int e = abs(b-c)+1; num(min(d, e)); return; } if (a == c && a != b) { if (a == 2 && b == 1) { cout << -1 << endl; return; } if (b+1 == a) { cout << 2 << endl; return; } if (b < a) { cout << 1 << endl; return; } if (a == 1) { num(-1); return; } num(1); return; } if (a == b && b != c) { if (c == 1 && a == 2) { num(-1); return; } if (a-c == 1) { num(2); return; } num(1); return; } if (a != b && b == c) { if (b != 1) { num(1); return; } num(-1); return; } if (a == b && b == c) { if (a < 3) { num(-1); return; } num(3); return; } } signed main() { int Q; cin >> Q; while (Q--) solve(); return 0; }