#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long power(long long a, long long b) {
  long long res = 1;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    a = a * a;
  }
  return res;
}
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long mul(long long a, long long b) { return (1LL * a * b) % 1000000007; }
long long add(long long a, long long b) {
  long long s = (a + b);
  if (s >= 1000000007) s -= 1000000007;
  return s;
}
long long sub(long long a, long long b) {
  long long s = (a + 1000000007 - b);
  if (s >= 1000000007) s -= 1000000007;
  return s;
}
void bWayne() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (a > b) {
    swap(a, b);
  }
  long long diff = b - a;
  long long total = 2 * diff;
  long long newdiff = total - b + a;
  if (total < b || newdiff != diff || b <= total / 2 || c > total) {
    cout << -1 << endl;
    return;
  }
  c += diff;
  if (c > total) c %= total;
  cout << c << endl;
}
int main() {
  bWayne();
  long long t = 1;
  cin >> t;
  for (long long tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
