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