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