#include #include #include #include #include #include #include using namespace std; using ll = long long; int f(int a, int b, int c) { int x = 0; if (a >= b) x += a - (b - 1), a = b - 1; if (c >= b) x += c - (b - 1), c = b - 1; if (a == c) x++, a--; if (a <= 0 || c <= 0) x = -1; return x; } int g(int a, int b, int c) { int x = 0; if (a == c) x++, a--; int t = min(a, c); if (b >= t) x += b - (t - 1), b = t - 1; if (a <= 0 || b <= 0) x = -1; return x; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { int a, b, c; cin >> a >> b >> c; int x = f(a, b, c); int y = g(a, b, c); int r; if (x < 0 && y < 0) r = -1; else if (x < 0) r = y; else if (y < 0) r = x; else r = min(x, y); cout << r << '\n'; } return 0; }