#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; const static ll INF = (ll)(1e15); bool isKadomatsu(int A, int B, int C){ if(A<=0 || B<=0 || C<=0) return false; map m; m[A] = 1; m[B] = 1; m[C] = 1; if(m.size() != 3) return false; vector v{A,B,C}; sort(ALLOF(v)); return (v[1]==A || v[1]==C); } ll check(int A, int B, int C, int tA, int tB, int tC){ if(!isKadomatsu(tA, tB, tC)) return INF; if(A cand; for(int i=-2; i<=2; i++) cand[A+i] = 1; for(int i=-2; i<=2; i++) cand[B+i] = 1; for(int i=-2; i<=2; i++) cand[C+i] = 1; vector v; FOR(it,cand) v.push_back(it->first); ll ret = INF; rep(i,v.size()){ rep(j,v.size()){ rep(k,v.size()){ ret = min(ret, check(A,B,C,v[i],v[j],v[k])); } } } if(ret == INF) return -1; return ret; } int main(){ int T; cin >> T; rep(t,T){ int A, B, C; cin >> A >> B >> C; cout << solve(A, B, C) << endl; } return 0; }