#include <bits/stdc++.h>
using namespace std;
const int N = 10100;
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    cin >> a >> b >> c;
    int d = fabs(a - b) * 2;
    if (a > d || c > d || b > d) {
      cout << "-1" << endl;
    } else {
      if (c > d / 2)
        cout << c - d / 2 << endl;
      else
        cout << c + d / 2 << endl;
    }
  }
  return 0;
}
