#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int t;
cin >> t;
long long a[3] = {};
while (t--) {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[0] == a[1] && a[1] == 0) {
cout << -1 << endl;
}
else if (a[0] == a[1] && a[1] == a[2] && a[2] == 1) {
cout << -1 << endl;
}
else if (a[0] == a[1] && a[1] == a[2] && a[2] == 0) {
cout << 0 << endl;
}
else if (a[0] == 0 && a[1] != a[2] && a[1] == 1) {
cout << -1 << endl;
}
else if (a[0] + a[1] == a[2]) {
cout << a[0] + a[1] << endl;
}
else if (a[0] + a[1] < a[2]) {
cout << a[0] + a[1] + ((a[2] - a[1] - a[0]) * 3) << endl;
}
else if (a[0] + a[1] > a[2]) {
long long ans;
long long x = a[1] - a[0];
a[1] = a[0];
a[2] -= x;
ans = x;
x = a[2] - a[0];
ans += x + x;
a[0] -= x;
a[1] = a[2] = a[0];
ans += (a[2] / 2) * 3;
if (a[0] % 2) {
ans += 4;
}
cout << ans << endl;
}
}
}
Copy