#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7ll, MAXN = 200069, INF = 2e18, MOD2 = 998244353;
void Master() {
  long long a, b, c;
  cin >> a >> b >> c;
  long long n = 2 * abs(b - a);
  long long ans1 = c + n / 2, ans2 = c - n / 2;
  if (ans2 <= 0) {
    ans2 += n;
  }
  if (ans1 >= n) {
    ans1 -= n;
  }
  if (a > n or b > n or c > n) {
    cout << -1 << '\n';
  } else if (ans1 >= 1 and ans1 <= n) {
    cout << ans1 << '\n';
  } else if (ans2 >= 1 and ans2 <= n) {
    cout << ans2 << '\n';
  } else {
    cout << -1 << '\n';
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tt = 1;
  cin >> tt;
  for (int tc = 1; tc <= tt; ++tc) {
    Master();
  }
  return 0;
}
