#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> d;
  while (d--) {
    cin >> a >> b >> c;
    int n = 2 * fabs(a - b);
    int e = n / 2;
    if (a > n || b > n || c > n)
      cout << -1 << endl;
    else if (c + e <= n)
      cout << c + e << endl;
    else if (c - e >= 1)
      cout << c - e << endl;
    else
      cout << -1 << endl;
  }
}
