#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cstdio>
#include <cmath>
#define int long long
using namespace std;
const int N = 2e5 + 10, M = 1e6 + 10, MOD = 998244353;
int a[N];
typedef pair<int, int> PII;
void solove() {
int x, y, z;
cin >> x >> y >> z;
if (x + y < z) cout << "-1\n";
rlse if (x < z)cout << "-1\n";
else if (x + y == z) cout << x + y + 5 << '\n';
else {
int t = x + y - z;
if ((x + y) % t == z) cout << t << '\n';
else cout << "-1\n";
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TT = 1;
cin >> TT;
while (TT--) {
solove();
}
return 0;
}