Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $1$. Each person is looking through the circle's center at the opposite person.

A sample of a circle of $6$ persons. The orange arrows indicate who is looking at whom.

You don't know the exact number of people standing in the circle (but this number is even, no doubt). It is known that the person with the number $a$ is looking at the person with the number $b$ (and vice versa, of course). What is the number associated with a person being looked at by the person with the number $c$? If, for the specified $a$, $b$, and $c$, no such circle exists, output -1.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

Each test case consists of one line containing three distinct integers $a$, $b$, $c$ ($1 \le a,b,c \le 10^8$).


-----Output-----

For each test case output in a separate line a single integer $d$ — the number of the person being looked at by the person with the number $c$ in a circle such that the person with the number $a$ is looking at the person with the number $b$. If there are multiple solutions, print any of them. Output $-1$ if there's no circle meeting the given conditions.


-----Examples-----

Input
7
6 2 4
2 3 1
2 4 10
5 3 4
1 3 2
2 5 4
4 3 2
Output
8
-1
-1
-1
4
1
-1


-----Note-----

In the first test case, there's a desired circle of $8$ people. The person with the number $6$ will look at the person with the number $2$ and the person with the number $8$ will look at the person with the number $4$.

In the second test case, there's no circle meeting the conditions. If the person with the number $2$ is looking at the person with the number $3$, the circle consists of $2$ people because these persons are neighbors. But, in this case, they must have the numbers $1$ and $2$, but it doesn't meet the problem's conditions.

In the third test case, the only circle with the persons with the numbers $2$ and $4$ looking at each other consists of $4$ people. Therefore, the person with the number $10$ doesn't occur in the circle.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	maxi = abs(a - b) * 2
	if maxi >= a and maxi >= b and (maxi >= c) and (abs(a - b) > 1):
		if c > abs(a - b):
			print(abs(c - abs(a - b)))
		else:
			print(c + abs(a - b))
	else:
		print(-1)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def input_list():
	return list(map(int, input().split()))

def input_string():
	s = input()
	return list(s[:len(s) - 1])

def input_int_gen():
	return map(int, input().split())
tests = inp()
for _ in range(tests):
	(a, b, c) = input_int_gen()
	halfsize = abs(a - b)
	size = halfsize * 2
	d = c + halfsize if c <= halfsize else c - halfsize
	if a > size or b > size or c > size:
		print(-1)
	else:
		print(d)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = abs(a - b)
	n = 2 * x
	if a > n or b > n or c > n:
		print(-1)
	elif c > x:
		print(c - x)
	else:
		print(c + x)


for s in [*open(0)][1:]:
	(a, b, c) = map(int, s.split())
	n = 2 * abs(a - b)
	print(((c - 1 + n // 2) % n + 1, -1)[max(a, b, c) > n])


import sys
input = sys.stdin.readline
t = int(input())
results = []
for i in range(t):
	(a, b, c) = map(int, input().rstrip().split())
	if a < b:
		(a, b) = (b, a)
	people = (a - b) * 2
	if a > people or c > people:
		results.append(-1)
	elif c + (a - b) > people:
		results.append((c + a - b) % people)
	else:
		results.append(c + a - b)
for i in results:
	print(i)


t = int(input())
lis = []
for i in range(t):
	(a, b, c) = map(int, input().split())
	ukup = abs(b - a) * 2
	if abs(b - a) * 2 >= a and abs(b - a) * 2 >= b and (abs(b - a) * 2 >= c):
		if c < ukup // 2:
			d = c + ukup // 2
			lis.append(d)
		elif c == ukup // 2:
			d = ukup
			lis.append(d)
		elif c > ukup // 2:
			d = c - ukup // 2
			lis.append(d)
	else:
		lis.append(-1)
for i in lis:
	print(i)


t = int(input())
while t:
	t -= 1
	(a, b, c) = [int(x) for x in input().split()]
	(a, b) = (min(a, b), max(a, b))
	if b < 2 * a:
		print(-1)
		continue
	mid = b - (a - 1)
	total = 2 * (mid - 2) + 2
	if c > total:
		print(-1)
		continue
	print(c + mid - 1 if c + mid - 1 <= total else c - mid + 1)


import math
import heapq
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	(a, b, c) = M()
	n = abs(b - a) * 2
	if a <= n and b <= n and (c <= n):
		if c + n // 2 > n:
			print(c - n // 2)
		else:
			print(c + n // 2)
	else:
		print(-1)


def code_input():
	amount = int(input())
	for _ in range(amount):
		(a, b, c) = input().split(' ')
		(a, b, c) = (int(a), int(b), int(c))
		if abs(a - b) == 1 or c > abs(a - b) * 2 or a > abs(a - b) * 2 or (b > abs(a - b) * 2):
			print(-1)
			continue
		if abs(a - b) >= c:
			print(abs(a - b) + c)
		else:
			print(c - abs(a - b))
code_input()


import sys

def input():
	return sys.stdin.readline().strip()

def ii():
	return int(input())

def mii():
	return map(int, input().split())

def lmii():
	return list(mii())
for _ in range(ii()):
	(a, b, c) = mii()
	n = abs(a - b)
	if any(map(lambda x: x > n * 2, (a, b, c))):
		print(-1)
	else:
		print(c + n if c + n <= n * 2 else c - n)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	mi = min(a, b)
	ma = max(a, b)
	re = ma - mi - 1
	to = 2 * re + 2
	if re == 0 or c > to or a > to or (b > to):
		print(-1)
	elif c > to // 2:
		print(c - to // 2)
	else:
		print(to // 2 + c)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	A = min(a, b)
	B = max(a, b)
	n = 2 * (B - A)
	if n < B:
		print(-1)
	elif n < c:
		print(-1)
	else:
		ans = c + (B - A)
		if ans > n:
			ans -= n
		print(ans)


for i in range(int(input())):
	(x, y, z) = map(int, input().split())
	if abs(x - y) * 2 >= max(x, y, z):
		new = abs(x - y) * 2
		if z + abs(x - y) > new:
			print((z + abs(x - y)) % new)
		else:
			print(z + abs(x - y))
	else:
		print('-1')


import sys
inp = sys.stdin.readline()
test = int(inp.strip('\n'))
result = ''
for _ in range(test):
	inp = sys.stdin.readline()
	(a, b, c) = list(map(int, inp.strip('\n').split()))
	d = abs(a - b)
	p = d * 2
	if c > p or a > p or b > p:
		result += '-1\n'
		continue
	if c - d > 0:
		result += str(c - d) + '\n'
	elif c + d <= p:
		result += str(c + d) + '\n'
	else:
		result += '-1\n'
sys.stdout.write(result)


for _ in [*open(0)][1:]:
	(a, b, c) = map(int, _.split())
	if a <= 2 * abs(a - b) and b <= 2 * abs(a - b) and (c <= 2 * abs(a - b)):
		if c <= abs(a - b):
			print(c + abs(a - b))
		else:
			print(c - abs(a - b))
	else:
		print(-1)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		(a, b, c) = get_ints()
		n = 2 * abs(a - b)
		if a > n or b > n or c > n:
			get_print_int(-1)
		else:
			mid = n // 2 + 1
			if a >= mid:
				other = 1 + (a - mid)
				if other != b:
					get_print_int(-1)
				elif c >= mid:
					get_print_int(1 + (c - mid))
				else:
					get_print_int(mid + (c - 1))
			else:
				other = mid + (a - 1)
				if other != b:
					get_print_int(-1)
				elif c >= mid:
					get_print_int(1 + (c - mid))
				else:
					get_print_int(mid + (c - 1))
solve()


import math

def iseven(n):
	return n % 2 == 0

def isprime(num):
	for i in range(2, num // 2):
		if num % i == 0:
			return False
	return True
t = int(input())
for _ in range(t):
	(a, b, c) = [int(x) for x in input().split()]
	n = abs(b - a) - 1
	n = 2 * n
	n += 2
	if iseven(n) and c <= n and (b <= n) and (a <= n):
		if 2 * c > n:
			print(c - abs(b - a))
		else:
			print(c + abs(b - a))
	else:
		print(-1)


import sys
input = sys.stdin.readline
from pprint import pprint
INF = 1 << 63

def do():
	(a, b, c) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	n2 = b - a
	allmember = n2 * 2
	if not (1 <= a <= n2 and n2 < b <= allmember):
		print(-1)
		return
	if 1 <= c <= n2:
		print(c + n2)
	elif n2 < c <= allmember:
		print(c - n2)
	else:
		print(-1)
q = int(input())
for _ in range(q):
	do()


g = int(input())
for i in range(g):
	(a, b, c) = map(int, input().split())
	vsego = abs(a - b) * 2
	if 1 <= a <= vsego and 1 <= b <= vsego and (a != b != c) and (1 <= c <= vsego):
		if 1 <= c + vsego // 2 <= vsego:
			print(c + vsego // 2)
		elif 1 <= c - vsego // 2 <= vsego:
			print(c - vsego // 2)
	else:
		print('-1')


import math

def solve():
	valor = input().split()
	a = int(valor[0])
	b = int(valor[1])
	c = int(valor[2])
	tam = abs(a - b)
	temp = tam
	tam = tam * 2
	if a <= tam and b <= tam and (c <= tam):
		if c - temp < tam and c - temp > 0:
			print(c - temp)
			return 0
		if c + temp <= tam:
			print(c + temp)
			return 0
	print('-1')
	return -1

def main():
	t = int(input())
	while t != 0:
		solve()
		t = t - 1
main()


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ans = max(a, b) - min(a, b)
	if c > ans * 2 or b > ans * 2 or a > ans * 2:
		print(-1)
	elif c + ans > ans * 2:
		print(c - ans)
	else:
		print(c + ans)


try:
	t = int(input())
	for i in range(t):
		(a, b, c) = input().split()
		halfcirclelen = int(a) - int(b)
		if halfcirclelen < 0:
			halfcirclelen = -1 * halfcirclelen
		if int(a) > halfcirclelen * 2 or int(b) > halfcirclelen * 2 or int(c) > halfcirclelen * 2:
			print(-1)
		elif int(c) + halfcirclelen > 2 * halfcirclelen:
			print(int(c) - halfcirclelen)
		else:
			print(int(c) + halfcirclelen)
except:
	pass


from sys import *
import math
input = stdin.readline
I = int
R = range
listInput = lambda : list(map(int, input().strip().split()))
lineInput = lambda : map(int, input().strip().split())
sJoin = lambda a, sep: '{}'.format(sep).join(a)
arrJoin = lambda a, sep: '{}'.format(sep).join(map(str, a))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(math.sqrt(n) + 1), 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def main():
	for _ in R(I(input())):
		(a, b, c) = lineInput()
		abcMax = max(a, b, c)
		dif = max(a, b) - min(a, b)
		total = dif * 2
		if abcMax > total:
			print(-1)
		elif c - dif >= 1:
			print(c - dif)
		elif c + dif <= total:
			print(c + dif)
		else:
			print(-1)
main()


def solve():
	(a, b, c) = [int(i) for i in input().split()]
	q = abs(a - b) * 2
	if 1 <= a and a <= q and (1 <= b) and (b <= q) and (1 <= c) and (c <= q):
		if c > q // 2:
			return c - q // 2
		return c + q // 2
	return -1
t = int(input())
ans = []
while t:
	ans.append(str(solve()))
	t -= 1
print('\n'.join(ans))


t = int(input())
mas = []
for i in range(t):
	(a, b, c) = input().split()
	(a, b, c) = (min(int(a), int(b)), max(int(a), int(b)), int(c))
	mas.append([a, b, c])
for i in mas:
	(a, b, c) = (i[0], i[1], i[2])
	part = b - a
	if part > 1:
		if c <= 2 * (b - a) and b - a > a - 1:
			if c <= b - a:
				print(b - a + c)
			else:
				print(c - b + a)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b, c) = [int(o) for o in input().split()]
	k = abs(a - b) * 2
	if a > k or b > k or c > k:
		print(-1)
	else:
		p = (c - 1 + k // 2) % k + 1
		print(p)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	s = abs(a - b) - 1
	get = 2 * (s + 1)
	mid = get // 2
	if a == mid and b != 2 * mid or (b == mid and a != 2 * mid):
		print(-1)
	elif min(a, b) + mid != max(b, a) or c > get or a > get or (b > get):
		print(-1)
	else:
		print(c + mid if c <= mid else max(c - mid, 1))


import sys, math
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
mod = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def li():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(a, b, c) = li()
	dif = abs(a - b)
	num = dif * 2
	if a > num or b > num or c > num:
		print(-1)
		continue
	if c + dif > num:
		if c - dif > 0:
			ans = c - dif
		else:
			ans = -1
	else:
		ans = c + dif
	print(ans)


import sys
from os import path
if path.exists('Input.txt'):
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')
input = lambda : sys.stdin.readline().rstrip()
from collections import deque
ff = []
for i in range(1700):
	if i % 3 != 0 and i % 10 != 3:
		ff.append(i)

def solve_tc():
	(a, b, c) = map(int, input().split())
	d = abs(a - b) * 2
	r = abs(a - b)
	if a > d or b > d or c > d:
		return -1
	if c - r > 0:
		return c - r
	if c + r <= d:
		return c + r
	return -1
t = int(input())
for _ in range(t):
	sys.stdout.write(str(solve_tc()) + '\n')


def solve(a, b, c):
	r = abs(a - b)
	if a > 2 * r or b > 2 * r or c > 2 * r:
		return -1
	if r + c <= 2 * r:
		return r + c
	if c - r >= 1:
		return c - r
	return -1
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	print(solve(a, b, c))


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(a, b, c) = map(int, input().split())
		if a > b:
			(a, b) = (b, a)
		v = b - a
		if b < 2 * a or c > b - a + v:
			print(-1)
			continue
		half = 1 + v
		if c < half:
			print(c + v)
		elif c == half:
			print(1)
		else:
			print(c - v)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	t = abs(a - b)
	if 2 * t < max(a, b, c):
		print(-1)
	elif c + t <= 2 * t:
		print(c + t)
	elif 2 * t >= c - t > 0:
		print(c - t)
	else:
		print(-1)


for j in range(int(input())):
	(a, b, c) = map(int, input().split())
	diff = max(a, b) - min(a, b)
	tot = 2 * diff
	if c > tot or max(a, b) > tot:
		print(-1)
	else:
		res = (diff + c - 1) % tot
		print(res + 1)


n = int(input())
r = []
for i in range(n):
	(a, b, c) = map(int, input().split())
	p = abs(a - b) * 2
	if abs(a - b) > 1 and p % 2 == 0 and (c <= p) and (a <= p) and (b <= p):
		r.append([abs(a - b) + c, abs(a - b) + c - p][abs(a - b) + c > p])
	else:
		r.append(-1)
for i in r:
	print(i)


cases = int(input())

def circlenator(a, b, c):
	half = abs(a - b)
	circ_size = half * 2
	if circ_size < a or circ_size < b or circ_size < c:
		return -1
	if c <= half:
		ans = c + half
	else:
		ans = c - half
	if ans <= circ_size and ans >= 1:
		return ans
	else:
		return -1
for case in range(cases):
	(a, b, c) = [int(x) for x in input().split()]
	print(circlenator(a, b, c))


import copy
import math
from sys import stdin

def A():
	t = int(stdin.readline())
	while t:
		t -= 1
		cnt = 0
		k = int(stdin.readline())
		i = 0
		while True:
			if i % 3 == 0 or i % 10 == 3:
				i += 1
				continue
			cnt += 1
			if cnt == k:
				break
			i += 1
		print(i)

def B():
	t = int(stdin.readline())
	while t:
		t -= 1
		(a, b, c) = [int(x) for x in stdin.readline().split()]
		k = abs(b - a)
		k1 = c + k
		if k * 2 < max(a, b, c):
			print(-1)
		elif k1 > k * 2:
			k1 = c - k
			if k1 >= 0:
				print(k1)
			else:
				print(-1)
		else:
			print(k1)

def C():
	t = int(stdin.readline())
	while t:
		t -= 1
		a = [int(x) for x in stdin.readline().split()]
B()


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_list_strings():
	return list(map(str, sys.stdin.readline().strip().split()))

def solve(a, b, c):
	req = abs(b - a)
	up = 2 * req
	if c > up:
		sys.stdout.write(str(-1) + '\n')
		return
	if max(b, a) > up:
		sys.stdout.write(str(-1) + '\n')
		return
	ans1 = c - req
	ans2 = c + req
	if ans1 <= up and ans1 >= 1:
		if (ans1 != a and ans1 != b) and ans1 != c:
			sys.stdout.write(str(ans1) + '\n')
			return
	if ans2 <= up and ans2 >= 1:
		if (ans2 != a and ans2 != b) and ans2 != c:
			sys.stdout.write(str(ans2) + '\n')
			return
	sys.stdout.write(str(-1) + '\n')
T = get_int()
while T:
	(a, b, c) = get_ints()
	solve(a, b, c)
	T -= 1


from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
from sys import stdin, stdout
input = stdin.readline
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
mt = lambda r: [ls() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)
for _ in range(it()):
	(a, b, c) = mp()
	cycle = abs(a - b)
	if c > 2 * cycle:
		print(-1)
	elif a > cycle and b > cycle:
		print(-1)
	elif a < cycle and b < cycle:
		print(-1)
	elif c + cycle <= 2 * cycle:
		print(c + cycle)
	else:
		print(c - cycle)


import sys, math, io, os, time, itertools, collections
mod = 10 ** 9 + 7
sys.setrecursionlimit(10000)
i = sys.stdin.readline
p = sys.stdout.write
global start, end

def isin(l, x):
	left = 0
	right = len(l) - 1
	if x < l[0]:
		return -1
	while left <= right:
		mid = left + (right - left) // 2
		if l[mid] == x:
			return mid
		elif l[mid] < x:
			ans = mid
			left = mid + 1
		else:
			right = mid - 1
	return ans

def ispal(l):
	n = len(l)
	for i in range(n // 2 + 1):
		if l[i] != l[n - i - 1]:
			return False
	return True

def ccarray(l):
	d = {l[k]: k for k in range(len(l))}
	m = sorted(d)
	return [d[m[k]] for k in range(len(l))]

def is_prime(n):
	if n <= 3:
		return n > 1
	if n % 2 == 0 or n % 3 == 0:
		return False
	k = 5
	while k ** 2 <= n:
		if n % k == 0 or n % (k + 2) == 0:
			return False
		k += 6
	return True

def sieve(n):
	prime = [True for k in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for k in range(p * p, n + 1, p):
				prime[k] = False
		p += 1

def main():
	(a, b, c) = [int(k) for k in i().split()]
	n = 2 * abs(a - b)
	d1 = c - abs(a - b)
	d2 = c + abs(a - b)
	if 0 < d1 <= n and c <= n and (a <= n) and (b <= n):
		p(str(d1) + '\n')
	elif 0 < d2 <= n and c <= n and (a <= n) and (b <= n):
		p(str(d2) + '\n')
	else:
		p('-1\n')
t = 1
t = int(i())
start = time.perf_counter()
for _ in range(t):
	main()
end = time.perf_counter()


ans = []
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = 2 * abs(a - b)
	for i in (a, b, c):
		if i > x:
			ans += [-1]
			break
	else:
		d1 = c + x // 2
		d2 = c - x // 2
		ans += [[d1], [d2]][1 <= d2 <= x]
print('\n'.join(map(str, ans)))


t = int(input())
n = []
for _ in range(t):
	(a, b, c) = map(int, input().split())
	d = -1
	if abs(a - b) * 2 >= c and abs(a - b) * 2 >= a and (abs(a - b) * 2 >= b):
		if c <= abs(a - b):
			d = c + abs(a - b)
		else:
			d = c - abs(a - b)
	n.append(d)
for i in n:
	print(i)


def main():
	t = int(input())
	for _ in range(t):
		(a, b, c) = [int(n) for n in input().split()]
		gap = abs(a - b) - 1
		people = gap * 2 + 2
		if gap == 0 or max(a, b, c) > people:
			print(-1)
		else:
			answer = (c + gap + 1) % people
			if answer == 0:
				answer = people
			print(answer)
main()


t = int(input())
for o in range(t):
	(a, b, c) = [int(i) for i in input().split()]
	if abs(a - b) * 2 < c or abs(a - b) * 2 < a or abs(a - b) * 2 < b:
		print(-1)
		continue
	if c <= abs(a - b):
		print(c + abs(a - b))
		continue
	print(c - abs(a - b))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = abs(a - b)
	if a <= 2 * d and b <= 2 * d and (c <= 2 * d):
		if c <= d:
			print(c + d)
		elif c <= 3 * d:
			print(c - d)
		else:
			print(-1)
	else:
		print(-1)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	cir = abs(a - b) * 2
	ch = abs(a - b)
	if a > cir or b > cir or c > cir or (ch == 1 and max(a, b) > 2):
		print(-1)
	else:
		ans = c - ch
		if ans <= 0:
			ans += cir
		print(ans)


for i in range(int(input())):
	(a, b, c) = [int(i) for i in input().split()]
	dif = abs(a - b)
	if 2 * dif < max(a, b) or c > 2 * dif:
		print(-1)
	elif c > dif:
		print(c - dif)
	else:
		print(c + dif)


t = int(input())
for n in range(t):
	nums = input().split(' ')
	a = int(nums[0])
	b = int(nums[1])
	c = int(nums[2])
	diff = abs(a - b)
	circle_players = diff * 2
	if c > circle_players or a > circle_players or b > circle_players:
		print(-1)
		continue
	d = c + diff
	if d > circle_players:
		d = abs(d - circle_players)
	print(d)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	size = max(a, b) - min(a, b)
	if size * 2 < c or size * 2 < a or size * 2 < b:
		print(-1)
		continue
	if c - size <= 0:
		print(c + size)
	else:
		print(c - size)


import sys
for t in range(int(sys.stdin.readline())):
	(a, b, c) = map(int, sys.stdin.readline().split())
	if a > b:
		(a, b) = (b, a)
	if b >= 2 * a:
		max_number = 2 * (b - a)
		if max_number < c:
			print(-1)
		elif b - a >= c:
			print(b - a + c)
		else:
			print(c - b + a)
	else:
		print(-1)


import sys
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, sys.stdin.readline().split())
	(a, b) = (min(a, b), max(a, b))
	max_num = 2 * (b - a)
	if c > max_num or b > max_num:
		print(-1)
	elif c > max_num // 2:
		print(c - max_num // 2)
	else:
		print(c + max_num // 2)


N = int(input())
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
	(a[i], b[i], c[i]) = [int(x) for x in input().split()]
for i in range(N):
	l = 2 * abs(a[i] - b[i])
	d = abs(a[i] - b[i])
	if l < 4 or a[i] > l or b[i] > l:
		print(-1)
		continue
	if c[i] <= l:
		if 0 < c[i] - d:
			print(c[i] - d)
		elif c[i] + d <= l:
			print(c[i] + d)
	else:
		print(-1)


import os, sys
from io import BytesIO, IOBase

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class dict(dict):

	def __missing__(self, key):
		return 0
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda dtype: dtype(input().strip())
inp_d = lambda dtype: [dtype(x) for x in input().split()]
inp_2d = lambda dtype, n: [inp(dtype) for _ in range(n)]
inp_2ds = lambda dtype, n: [inp_d(dtype) for _ in range(n)]
inp_enu = lambda dtype: [(i, x) for (i, x) in enumerate(inp_d(dtype))]
inp_enus = lambda dtype, n: [[i] + [inp_d(dtype)] for i in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
for _ in range(inp(int)):
	(a, b, c) = inp_d(int)
	(mi, ma) = (min(a, b), max(a, b))
	(a, b) = (1, ma - mi + 1)
	cir = (b - a) * 2
	if cir < max(ma, c):
		print(-1)
	else:
		print(c - (b - a) if c > b - a else c + (b - a))


t = int(input())
for i in range(t):
	triples = input()
	hi = triples.split()
	a = int(hi[0])
	b = int(hi[1])
	c = int(hi[2])
	a_minus_b = abs(a - b)
	total_num = 2 * a_minus_b
	if a > total_num or b > total_num or c > total_num:
		print('-1')
	elif c + a_minus_b > total_num:
		print(c - a_minus_b)
	else:
		print(c + a_minus_b)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	k = abs(b - a)
	if k * 2 < max(a, b, c):
		print('-1')
	elif c > k:
		print(int(c - k))
	elif k > c:
		print(int(c + k))
	else:
		print(int(c + k))


t = int(input())
v = []
for i in range(t):
	(a, b, c) = map(int, input().split())
	if b < a:
		(a, b) = (b, a)
	r = b - a
	k = r * 2
	if a > k or b > k or c > k or (c + r > k and c - r < 1):
		v.append(-1)
	elif c > r:
		v.append(c - r)
	else:
		v.append(c + r)
for i in range(t):
	print(v[i])


import string
import math
import sys
input = sys.stdin.buffer.readline
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
MOD = 1000000007

def preprocess():
	pass

def solve():
	(a, b, c) = list(map(int, input().split()))
	diff = abs(a - b)
	len = 2 * diff
	if a > len or b > len or c > len:
		print(-1)
		return
	if c + diff <= len and c + diff >= 1 and (c + diff != a) and (c + diff != b):
		ans = c + diff
	elif c - diff >= 1 and c - diff <= len and (c - diff != a) and (c - diff != b):
		ans = c - diff
	else:
		ans = -1
	print(ans)
t = int(input())
while t > 0:
	solve()
	t -= 1


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(a, b, c) = [int(s) for s in stdin.readline().split()]
	n = (abs(b - a) - 1) * 2 + 2
	if n == 2 or max(a, b, c) > n:
		print(-1)
	else:
		print((c + abs(b - a)) % n if c + abs(b - a) > n else c + abs(b - a))


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	n = abs(a - b)
	t = 2 * n
	if max([a, b, c]) <= t:
		d = c + n
		if d > t:
			d = d % t
		print(d)
	else:
		print(-1)


n = int(input())
for i in range(n):
	input_str = input()
	(a, b, c) = input_str.split()
	(a, b, c) = (int(a), int(b), int(c))
	no_of_element = abs(a - b) * 2
	diff = abs(a - b)
	if (max(a, b) or min(a, b)) > no_of_element:
		print(-1)
	elif c > no_of_element:
		print(-1)
	elif c + diff <= no_of_element:
		print(c + diff)
	else:
		print(c - diff)


t = int(input())
while t > 0:
	l = list(map(int, input().split(' ')[:3]))
	m = max(l[0], l[1])
	n = min(l[0], l[1])
	d = m - n
	if max(l[0], l[1], l[2]) > 2 * d:
		print('-1')
	elif l[2] <= d:
		print(l[2] + d)
	else:
		print(l[2] - d)
	t -= 1


from collections import Counter
import math
from bisect import bisect
import sys
MOD = 1000000007
MAX = sys.maxsize
MIN = -sys.maxsize

class get:

	def int():
		return list(map(int, input().split()))

	def str():
		return input().split()

	def float():
		return list(map(float, input().split()))

	def map():
		return map(int, input().split())

def sqrt(x):
	return int(math.sqrt(x)) + 1

def gcd(*args):
	result = args[0]
	for item in args:
		result = math.gcd(result, item)
	return result

def LCM(a, b):
	return a * b // math.gcd(a, b)

def solve():
	(a, b, c) = get.map()
	diff = abs(a - b)
	circle = 2 * diff
	if diff < 2:
		print(-1)
	elif a > circle or b > circle or c > circle:
		print(-1)
	else:
		k1 = c + diff
		k2 = c - diff
		if k1 > 0 and k1 <= circle:
			print(k1)
		else:
			print(k2)
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	v = abs(a - b)
	if max(a, b) < 2 * min(a, b) or v * 2 < c:
		print('-1')
	elif 2 * v >= c + v:
		print(v + c)
	else:
		print(c - v)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	half = max(a, b) - min(a, b)
	total = half * 2
	if c > total or max(a, b) > total:
		print(-1)
	elif (c + half) % total == 0:
		print(c + half)
	else:
		print((c + half) % total)


n = int(input())
for i in range(0, n):
	temp = []
	temp = list(map(int, input().split()))
	radius = abs(temp[0] - temp[1])
	if temp[0] > temp[1]:
		(temp[0], temp[1]) = (temp[1], temp[0])
	if temp[2] > radius * 2 or radius <= 1 or temp[1] > radius * 2:
		print('-1')
	elif temp[2] + radius == radius * 2:
		print(radius * 2)
	else:
		print((temp[2] + radius) % (radius * 2))


n = int(input())
for i in range(0, n):
	(a, b, c) = list(map(int, input().strip().split()))
	m = a - b
	if m < 0:
		m = m * -1
	m = m * 2
	if a > m or b > m or c > m:
		print(-1)
		continue
	ot = c + m // 2
	if ot > m:
		ot = ot - m
	print(ot)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	n = abs(a - b) * 2
	if (a <= n // 2) == (b <= n // 2):
		print(-1)
		continue
	if c > n:
		print(-1)
		continue
	print(c + n // 2 if c <= n // 2 else c - n // 2)


import math
import sys
from decimal import Decimal

def main(a, b, c):
	if a > b:
		(a, b) = (b, a)
	n = 2 * (b - a)
	if c > n or b > n or a > n:
		return -1
	ans = (c + n // 2) % n
	if ans == 0:
		return n
	return ans
t = int(input())
ans = []
for i in range(t):
	(a, b, c) = list(map(int, input().split()))
	ans.append(main(a, b, c))
for e in ans:
	print(e)


def main():
	answer = []
	test_case = int(input())
	i = 0
	while i < test_case:
		find_total_people(answer)
		i += 1
	for person in answer:
		print(person)

def find_total_people(answer_list):
	(a, b, c) = map(int, input().split(' '))
	d = 0
	total = abs(a - b) * 2
	ref = total // 2
	if total >= a and total >= b and (total >= c):
		if c <= ref:
			answer_list.append(ref + c)
		elif c > ref:
			answer_list.append(c - ref)
	else:
		answer_list.append(-1)
main()


from sys import stdin, stdout
input = stdin.readline

def output(answer):
	stdout.write('{}\n'.format(answer))
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	prev = a - 1
	diff = b - a
	if diff <= prev:
		output(-1)
		continue
	total = b - prev - 1
	if c > total * 2:
		output(-1)
		continue
	if c <= total:
		output(c + diff)
	else:
		output(c - diff)


import math
t = int(input())
list = []
while t > 0:
	s = input()
	list.append(s.split(' '))
	t = t - 1
for Klist in list:
	Klist[0] = int(Klist[0])
	Klist[1] = int(Klist[1])
	Klist[2] = int(Klist[2])
	num = abs(Klist[0] - Klist[1]) * 2
	n = -1
	if Klist[0] <= num and Klist[1] <= num:
		if Klist[2] <= num:
			if Klist[2] > num / 2:
				n = Klist[2] - num / 2
			else:
				n = Klist[2] + num / 2
			if n == Klist[0] or n == Klist[1]:
				print('-1')
			else:
				print(int(n))
		else:
			print('-1')
	else:
		print('-1')


def good(a, b, n):
	(a, b) = (min(a, b), max(a, b))
	diff1 = b - a
	diff2 = n - b + a
	if diff1 != diff2:
		return False
	return True

def solve(a, b, c, ans):
	(a, b) = (min(a, b), max(a, b))
	diff1 = b - a
	n = 2 * diff1
	diff2 = n - b + a
	if diff1 != diff2 or c > n or b > n:
		ans.append('-1')
		return
	d = (c + diff1) % n
	if d == 0:
		d = n
	if not good(c, d, n):
		ans.append('-1')
		return
	ans.append(str(d))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(a, b, c) = map(int, input().split())
		solve(a, b, c, ans)
	print('\n'.join(ans))
main()


numbers = input()
numbers = int(numbers)
a = []
b = []
c = []
for i in range(1, numbers + 1):
	(num1, num2, num3) = input().split(' ', 2)
	num1 = int(num1)
	num2 = int(num2)
	num3 = int(num3)
	a.append(num1)
	b.append(num2)
	c.append(num3)
for k in range(1, numbers + 1):
	total = 2 * (abs(a[k - 1] - b[k - 1]) - 1) + 2
	if total < max(a[k - 1], b[k - 1], c[k - 1]):
		print('-1')
	else:
		d = c[k - 1] + abs(a[k - 1] - b[k - 1])
		if d <= total:
			print(d)
		else:
			d = c[k - 1] - abs(a[k - 1] - b[k - 1])
			print(d)


t = int(input())
for i in range(t):
	X = input().split()
	a = int(X[0])
	b = int(X[1])
	c = int(X[2])
	Max = max(a, b) + 1
	Min = min(a, b)
	if (Max - 1) % 2 == 0:
		if Min <= Max // 2:
			nop = 2 * abs(a - b)
			if c > nop:
				print(-1)
			elif c > abs(a - b):
				print(c - abs(a - b))
			else:
				print(c + abs(a - b))
		else:
			print(-1)
	elif Min < Max // 2:
		nop = 2 * abs(a - b)
		if c > nop:
			print(-1)
		elif c > abs(a - b):
			print(c - abs(a - b))
		else:
			print(c + abs(a - b))
	else:
		print(-1)


import sys, math, itertools
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in wtf[1:]:
	(a, b, c) = map(int, t.split())
	d = abs(a - b)
	N = 2 * d
	if c > N or max(a, b) > N:
		print(-1)
	else:
		print(abs(c - d) if c > d else c + d)


n = int(input())
for i in range(n):
	t = list(input().split())
	t = [int(j) for j in t]
	dif = abs(t[0] - t[1])
	size = dif * 2
	if size < t[2]:
		print(-1)
	elif t[0] > size or t[1] > size:
		print(-1)
	elif size < t[2] * 2:
		print(t[2] - dif)
	else:
		print(t[2] + dif)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
t = iinput()
for _ in range(t):
	(a, b, c) = rinput()
	s = max(a, b) - min(a, b)
	l = max(a, b, c)
	if l > 2 * s:
		print(-1)
	elif c <= s:
		print(c + s)
	else:
		print(c - s)


tests = int(input())
arr = []
for x in range(tests):
	inp = list(map(int, input().split()))
	arr.append(inp)
out = []
for y in range(len(arr)):
	size = abs(arr[y][0] - arr[y][1])
	if arr[y][2] > size * 2 or arr[y][1] > size * 2 or arr[y][0] > size * 2:
		out.append(-1)
		continue
	if arr[y][2] - size < 1 and arr[y][2] + size > size * 2:
		out.append(-1)
	elif arr[y][2] - size < 1:
		if arr[y][2] + size == arr[y][0] or arr[y][2] + size == arr[y][1]:
			out.append(-1)
			continue
		out.append(arr[y][2] + size)
	elif arr[y][2] + size > size * 2:
		if arr[y][2] - size == arr[y][0] or arr[y][2] - size == arr[y][1]:
			out.append(-1)
			continue
		out.append(arr[y][2] - size)
for _ in out:
	print(_)


def ispossible(a, b, c):
	n = abs(a - b) - 1
	n = 2 * n + 2
	if a > n or b > n or c > n:
		return -1
	a = abs(a - b)
	o1 = c - a
	o2 = c + a
	if o2 <= n:
		return o2
	if o1 >= 0:
		return o1
	return -1
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	print(ispossible(a, b, c))


t = int(input())
for i in range(t):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	n = 2 * abs(a - b)
	if a <= n and b <= n and (c <= n):
		if c > n / 2:
			print(c - abs(a - b))
		else:
			print(c + abs(a - b))
	else:
		print('-1')


t = int(input())
results = []
for i in range(t):
	(a, b, c) = map(int, input().split())
	dif = max(a, b) - min(a, b)
	total = 2 * dif
	if total < max(a, b):
		results.append(-1)
	elif c - dif > 0 and c <= total:
		results.append(c - dif)
	elif c + dif <= total and c > 0:
		results.append(c + dif)
	else:
		results.append(-1)
for i in range(t):
	print(results[i])


for _ in range(int(input())):
	(a, b, c) = [int(x) for x in input().split()]
	lal = abs(a - b)
	total = lal * 2
	if max(a, b) > total:
		print(-1)
		continue
	(a, b) = (max(a, b), min(a, b))
	if not (a > lal and b <= lal):
		print(-1)
		continue
	if c > lal:
		if c - lal <= lal:
			print(c - lal)
		else:
			print(-1)
	elif c + lal > total:
		print(-1)
	else:
		print(c + lal)


def onwitchpos(a, b, c):
	n = (max(a, b) - min(a, b)) * 2
	if max(a, b) > n:
		return -1
	if c > n / 2 and c <= n:
		return int(c - n / 2)
	elif c <= n / 2 and c > 0:
		return int(c + n / 2)
	else:
		return -1
for i in range(int(input())):
	n = input()
	arrn = n.split(' ')
	print(onwitchpos(int(arrn[0]), int(arrn[1]), int(arrn[2])))


t = int(input())
l = []

def solve(a, b, c):
	pn = 2 * abs(a - b)
	if c > pn or a > pn or b > pn:
		return -1
	ans = c + pn / 2
	if ans > pn:
		ans = c - pn / 2
	return ans
for _ in range(t):
	(a, b, c) = list(map(int, input().split()))
	m = solve(a, b, c)
	l.append(m)
for i in l:
	print(int(i))


n = int(input())
o = []
for i in range(n):
	(a, b, c) = map(int, input().split())
	if abs(a - b) == 1:
		o.append(-1)
	elif abs(a - b) < min(a, b):
		o.append(-1)
	else:
		if a > b:
			raznica = a - b
			crug = a - b - 1
			b1 = b - 1
			crug = a + crug - b1
		else:
			raznica = b - a
			crug = b - a - 1
			a1 = a - 1
			crug = b + crug - a1
		if c > crug:
			o.append(-1)
		elif c + raznica > crug:
			o.append(c + raznica - crug)
		else:
			o.append(c + raznica)
for i in range(n):
	print(o[i])


t = int(input())
res = []
for i in range(t):
	(a, b, c) = list(map(int, input().split()))
	r = abs(a - b)
	a1 = c + r
	a2 = c - r
	if r * 2 < a or r * 2 < b or r * 2 < c:
		res.append(-1)
	elif a2 != 0 and a2 != a and (a2 != b) and (a2 > 0) and (r * 2 >= a2):
		res.append(a2)
	elif a1 != 0 and a1 != a and (a1 != b) and (a1 > 0) and (r * 2 >= a1):
		res.append(a1)
	else:
		res.append(-1)
for i in res:
	print(i)


tc = int(input())
ans = []
for i in range(tc):
	n = [int(x) for x in input().split()]
	circle = abs(n[1] - n[0]) * 2
	if max(n[1], n[0]) > circle or n[2] > circle:
		ans.append(-1)
	elif n[2] > circle / 2:
		ans.append(n[2] - circle / 2)
	else:
		ans.append(n[2] + circle / 2)
for i in ans:
	print(int(i))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	x = min(a, b)
	y = max(a, b)
	a = x
	b = y
	d = b - a - 1
	e = a - 1
	x = b + d - e
	if c > x or x % 2 == 1 or d == 0 or (b > x):
		print(-1)
	else:
		y = b - a
		if c + y > x and c - y < 0:
			print(-1)
		elif c > y:
			print(c - y)
		else:
			print(c + y)


for iii in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	itog = abs(a - b) * 2
	if c > itog:
		print(-1)
		continue
	if abs(a - b) == 1 and (not (a == 1 or b == 1)):
		print(-1)
		continue
	if abs(a - b) - 1 < min(a, b) - 1:
		print(-1)
		continue
	x = max(a, b) - min(a, b) + c
	if x > itog:
		x = x % itog
	print(x)
	continue
	print('x')


for tt in range(int(input())):
	(a, b, c) = map(int, input().split())
	diff = abs(a - b)
	diff *= 2
	if a > diff or diff < b or diff < c:
		print(-1)
		continue
	if c > diff // 2:
		print((c + diff // 2) % diff)
	else:
		print(c + diff // 2)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	size = abs(a - b) * 2
	if size < max(a, b, c):
		print(-1)
	elif c + size // 2 <= size:
		print(c + size // 2)
	else:
		print(c - size // 2)


t = int(input())
res = []
for _ in range(t):
	(a, b, c) = map(int, input().split())
	cnt = abs(a - b) * 2
	if a > cnt or b > cnt or c > cnt:
		res.append(-1)
		continue
	if c > cnt // 2:
		res.append(c - cnt // 2)
	else:
		res.append(c + cnt // 2)
for el in res:
	print(el)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	l = abs(a - b) * 2
	if max(a, b, c) > l:
		print(-1)
		continue
	r = c + abs(a - b)
	r = r % l if r != l else r
	print(-1 if abs(r - c) * 2 != l else r)


t = int(input())
for i in range(t):
	(a, b, c) = input().split()
	f = max(int(a), int(b))
	g = min(int(a), int(b))
	m = (f - g) * 2
	k = f - g
	if m >= f and m >= int(c):
		if k + int(c) <= m:
			print(k + int(c))
		else:
			print(int(c) - k)
	else:
		print('-1')


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	dif = abs(a - b)
	n = dif * 2
	if a > n or b > n or c > n:
		print(-1)
	elif c + dif <= n:
		print(c + dif)
	elif c - dif <= n and c - dif > 0:
		print(c - dif)
	else:
		print(-1)


for _ in range(int(input())):
	[a, b, c] = list(map(int, input().split()))
	N = 2 * abs(a - b)
	if a > N or b > N or c > N:
		print(-1)
	elif c <= N / 2:
		print(c + abs(a - b))
	else:
		print(c - abs(a - b))


import sys
import math
from collections import Counter
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	less = min(a, b)
	more = max(a, b)
	n = 2 * (more - less)
	if c > n or more > n:
		print(-1)
	elif c + n // 2 > n:
		print(c + n // 2 - n)
	else:
		print(c + n // 2)


from sys import *
import math

def solve_case(t):
	(a, b, c) = [int(x) for x in stdin.readline().rstrip().split()]
	circle_size = abs(a - b) * 2
	if a > circle_size or b > circle_size or c > circle_size:
		print(-1)
	else:
		d = c + math.floor(circle_size / 2)
		if d > circle_size:
			d = d - circle_size
		print(d)

def main():
	T = int(stdin.readline())
	for t in range(T):
		solve_case(t)
main()


import sys

def solve():
	(a, b, c) = sys.stdin.readline().split()
	a = int(a)
	b = int(b)
	c = int(c)
	num = abs(a - b)
	if max(a, b, c) > 2 * num:
		print(-1)
		return
	if c <= num:
		print(c + num)
	else:
		print(c - num)
n = int(sys.stdin.readline())
for i in range(n):
	solve()


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = abs(a - b) * 2
	if b > d or a > d or c > d:
		print(-1)
	else:
		e = c + d // 2
		if e > d:
			e = c - d // 2
		print(e)


from sys import stdin
test = int(stdin.readline())
while test:
	(a, b, c) = [int(x) for x in input().split()]
	res = 2 * abs(a - b)
	if a > res or b > res or c > res:
		print('-1')
	else:
		sam = c + res // 2
		if sam > res:
			sam = c - res // 2
		print(sam)
	test -= 1


for s in [*open(0)][1:]:
	(a, b, c) = map(int, s.split())
	half = abs(b - a)
	total = 2 * half
	print(((c + half - 1) % total + 1, -1)[max(a, b, c) > total])


def finding_opposite(a, b, c):
	if a > b:
		dif = a - b - 1
	elif b > a:
		dif = b - a - 1
	opp_1 = 1 + dif + 1
	largest = opp_1 + dif
	opp_c = c + dif + 1
	if a > largest or largest < b:
		return -1
	elif dif == 0:
		return -1
	elif (dif + 1) * 2 == largest:
		if c > largest:
			return -1
		elif opp_c > largest:
			opp_c = c - dif - 1
			if opp_c <= 0:
				return -1
			else:
				return opp_c
		else:
			return opp_c
	else:
		return -1
t = int(input())
test_case_list_2D = []
for test_case in range(t):
	list = []
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	list.append(a)
	list.append(b)
	list.append(c)
	test_case_list_2D.append(list)
for list_test in test_case_list_2D:
	a = list_test[0]
	b = list_test[1]
	c = list_test[2]
	y = finding_opposite(a, b, c)
	print(y)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	ma = max(max(a, b), c)
	check = 2 * abs(b - a)
	if check < ma:
		print(-1)
	else:
		ans = (c + check // 2) % check
		if ans == 0:
			ans = check
		print(ans)


my_value = []
for i in range(int(input())):
	(a, b, c) = [int(x) for x in input().split()]
	distance = abs(b - a)
	total = distance * 2
	mid = 1 + distance
	if mid < min(a, b) or mid > max(a, b) or c > total or (mid in (a, b) and min(a, b) != 1):
		my_value.append(-1)
	elif c >= mid:
		temp = c - distance
		if temp >= mid:
			my_value.append(-1)
		else:
			my_value.append(temp)
	else:
		temp = c + distance
		if temp > total or temp < mid:
			my_value.append(-1)
		else:
			my_value.append(temp)
for i in my_value:
	print(i)


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
	(a, b, c) = get_int()
	if a > b:
		(a, b) = (b, a)
	diff = abs(a - b)
	sm = a + diff
	if diff < a:
		sm = a - diff
	if sm == b and diff * 2 >= c:
		ans = c + diff
		if diff < c:
			ans = c - diff
		print(ans)
	else:
		print(-1)


a = int(input())
i = 0
while i < a:
	b = input().split(' ')
	c = int(b[0])
	d = int(b[1])
	e = int(b[2])
	f = 0
	r = (max(c, d) - min(c, d)) * 2
	if c > r or d > r or e > r:
		f = f + 1
	if f == 0:
		if r // 2 + e <= r:
			print(r // 2 + e)
		if e - r // 2 > 0:
			print(e - r // 2)
	if f == 1:
		print(-1)
	i = i + 1


for i in range(int(input())):
	a = list(map(int, input().split(' ')))
	x = min(a[0], a[1])
	y = max(a[0], a[1])
	if y >= 2 * x:
		if a[2] <= 2 * abs(x - y):
			if a[2] + y - x <= 2 * (y - x):
				print(a[2] + y - x)
			else:
				print(a[2] - y + x)
		else:
			print('-1')
	else:
		print('-1')


trails = int(input())
answer_list = []
for x in range(trails):
	numbers = input().split(' ')
	a = int(numbers[0])
	b = int(numbers[1])
	c = int(numbers[2])
	dif = abs(a - b)
	length = 2 * dif
	if c > length or a > length or b > length:
		answer = -1
		answer_list.append(answer)
		continue
	if c > dif:
		answer = c - dif
	else:
		answer = c + dif
	answer_list.append(answer)
for g in answer_list:
	print(g)


n = int(input())
ans = []
for i in range(n):
	abc = input().split()
	a = int(abc[0])
	b = int(abc[1])
	c = int(abc[2])
	if a > b:
		sxva = a - b
	else:
		sxva = b - a
	elem = sxva * 2
	if a > elem or b > elem or c > elem:
		ans.append(-1)
	elif c + sxva <= elem:
		ans.append(c + sxva)
	else:
		ans.append(c - sxva)
for i in ans:
	print(i)


t = int(input())
while t != 0:
	t = t - 1
	(a, b, c) = map(int, input().split(' '))
	diff = abs(a - b)
	max1 = diff * 2
	if a <= max1 and b <= max1 and (c <= max1):
		if c + diff <= max1:
			print(c + diff)
		elif c - diff > 0:
			print(c - diff)
		else:
			print(-1)
	else:
		print(-1)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	r = max(a, b) - min(a, b)
	d = r + c
	ne = r - 1
	z = min(a, b) - ne
	if z <= 1 and c <= 2 * r:
		if d <= 2 * r:
			print(d)
		else:
			d = d - 2 * r
			print(d)
	else:
		print('-1')


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	k = b - a
	if b > 2 * k or c > 2 * k:
		print(-1)
		continue
	if c > k:
		print(c - k)
		continue
	print(c + k)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().strip().split())
	diff = abs(a - b)
	maxx = diff * 2
	if c > maxx or a > maxx or b > maxx:
		print(-1)
	elif diff == 1:
		print(-1)
	else:
		ans = c + diff
		if ans > maxx:
			print(ans - maxx)
		else:
			print(ans)


import sys

def main():
	num_args = None
	for line in sys.stdin:
		if not num_args:
			num_args = int(line)
			continue
		solve(line)

def solve(i):
	result = None
	(i, j, k) = i.split(' ')
	i = int(i)
	j = int(j)
	k = int(k)
	size = abs(i - j) * 2
	if k == j or k == i:
		result = -1
	elif k > size or j > size or i > size:
		result = -1
	else:
		result = int((k + size / 2) % size)
		if not result:
			result = int(size)
		if result == j or result == i:
			result = -1
	sys.stdout.write(str(result) + '\n')
main()


def find(k):
	(k[0], k[1], k[2]) = (int(k[0]), int(k[1]), int(k[2]))
	diff = abs(k[0] - k[1])
	len_of_circle = diff * 2
	if k[0] > len_of_circle or k[1] > len_of_circle or k[2] > len_of_circle:
		return -1
	elif k[2] + diff > len_of_circle:
		return k[2] - diff
	else:
		return k[2] + diff
l1 = []
t = int(input())
for i in range(t):
	l1.append(input().split(' '))
for i in range(len(l1)):
	print(find(l1[i]))


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	tmp = abs(a - b)
	check = tmp * 2
	if check < c or check < a or check < b:
		print(-1)
	else:
		print(c + tmp * ((c <= tmp) * 2 - 1))


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math
INT_MAX = 10 ** 13
from bisect import bisect_left
import sys
MOD = 10 ** 9 + 7
inf = MOD ** 2
from decimal import *
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = abs(a - b)
	n = 2 * d
	if c > n or a > n or b > n:
		print(-1)
		print()
		continue
	if c - d > 0:
		print(c - d)
	else:
		print(c + d)
	print()


for s in [*open(0)][1:]:
	(a, b, c) = map(int, s.split())
	d = abs(a - b)
	print((-1, c - d, c + d)[max(0, -c // d + 3) * (a <= 2 * d >= b)])


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split(' '))
	M = 2 * (abs(b - a) - 1) + 2
	if a > M or b > M or c > M:
		print(-1)
	else:
		print((c + abs(b - a) - 1) % M + 1)


def func(a, n):
	if a >= 1 and a <= n:
		return True
	return False
for _ in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	n = 2 * abs(a - b)
	if func(a, n) and func(b, n) and func(c, n):
		d1 = c + n // 2
		d2 = c - n // 2
		if func(d1, n) == True:
			print(d1)
		elif func(d2, n) == True:
			print(d2)
		else:
			print(-1)
	else:
		print(-1)


from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
L = lambda : list(M())
mod = 1000000007
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	(a, b, c) = M()
	if a < b:
		(a, b) = (b, a)
	if b > a - b or c > (a - b) * 2:
		print(-1)
		return
	if c > a - b:
		print(c - a + b)
	else:
		print(a - b + c)
tt = 1
tt = I()
for _ in range(tt):
	solve()


def do(t, nabor):
	max = 0
	for n in nabor:
		delta = n[0] - n[1]
		if delta < 0:
			delta = -delta
		all = 2 * delta
		if n[0] > all or n[1] > all or n[2] > all or (n[0] == n[1]):
			print(-1)
		elif n[2] > delta and n[2] - delta <= all:
			print(n[2] - delta)
		elif n[2] <= delta and n[2] + delta <= all:
			print(n[2] + delta)
		else:
			print(-1)

def main():
	t = int(input())
	nabor = []
	for _ in range(t):
		(a, b, c) = map(int, input().split())
		nabor.append((a, b, c))
	do(t, nabor)
main()


cases = int(input())
answers = []
for _ in range(cases):
	a_b_c = input().split(' ')
	(a, b, c) = (int(a_b_c[0]), int(a_b_c[1]), int(a_b_c[2]))
	total_nums = abs(int(a) - int(b)) * 2
	if a > total_nums or b > total_nums or c > total_nums or (a - b == 0):
		answers.append('-1')
	else:
		distance = abs(a - b)
		if c <= distance:
			answers.append(str(c + distance))
		else:
			answers.append(str(c - distance))
print('\n'.join(answers))


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	half = abs(a - b)
	total = half * 2
	if a > total or b > total or c > total:
		print(-1)
		continue
	if c > half:
		test = c - half
	else:
		test = c + half
	if test in range(1, total + 1):
		print(test)
	else:
		print(-1)


import sys

def input():
	return sys.stdin.readline().strip()

def ints():
	return map(int, input().split())
T = int(input())
for _ in range(T):
	(a, b, c) = ints()
	half = abs(b - a)
	if any((i > half * 2 for i in [a, b, c])):
		print(-1)
	else:
		print((c + half - 1) % (half * 2) + 1)


def find_d(pos_a, pos_b, pos_c):
	if pos_a > pos_b:
		max = pos_a
		pos_a = pos_b
		pos_b = max
	pos_d = -1
	if pos_b < pos_a * 2:
		return pos_d
	num_people = 2 * (pos_b - pos_a)
	if pos_c > num_people:
		return pos_d
	elif pos_c > num_people / 2:
		pos_d = pos_c - num_people / 2
	else:
		pos_d = pos_c + num_people / 2
	return int(pos_d)
t = int(input())
output = []
for _ in range(t):
	(a, b, c) = map(int, input().split())
	output.append(find_d(a, b, c))
for number in output:
	print(number)


import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]

def next():
	return tokens.pop()

def nextInt():
	return int(next())

def nextFloat():
	return float(next())

def getIntArray(n):
	return [nextInt() for _ in range(n)]

def getFloatArray(n):
	return [nextFloat() for _ in range(n)]

def getStringArray(n):
	return [next() for _ in range(n)]
flush = sys.stdout.flush
testcase = True

def solve(testcase=1):
	pass
	(A, B, C) = (nextInt(), nextInt(), nextInt())
	L = abs(A - B)
	if max(A, B, C) > L * 2:
		print(-1)
		return
	P = (C - 1 + L) % (2 * L) + 1
	print(P)
if testcase is None:
	while tokens:
		solve()
else:
	testcaseCount = nextInt() if testcase else 1
	for tc in range(testcaseCount):
		solve(tc + 1)
	assert not tokens


n = int(input())
sets = [list(map(int, input().split())) for _ in range(n)]
for (a, b, c) in sets:
	count = abs(a - b) * 2
	d = c + count // 2
	if d > count:
		d = c - count // 2
	if d > count or c > count or d == a or (d == b) or (c == a) or (c == b) or (count == 2) or (a > count) or (b > count):
		print(-1)
	else:
		print(d)


for s in [*open(0)][1:]:
	(a, b, c) = map(int, s.split())
	(b, a) = (max(a, b), min(a, b))
	if b < 2 * a or c > 2 * (b - a):
		print(-1)
		continue
	n = 2 * (b - a)
	print((b - a + c - 1) % n + 1)


n = int(input())
for _ in range(n):
	(a, b, c) = map(int, input().split(' '))
	d = abs(a - b)
	if c > d:
		res = c - d
	else:
		res = c + d
	if res > 0 and res <= 2 * d and (a <= 2 * d) and (b <= 2 * d) and (c <= 2 * d):
		print(res)
	else:
		print('-1')


n = int(input())
l = []
for i in range(n):
	r = list(map(int, input().split()))
	(a, b, c) = (r[0], r[1], r[2])
	d = abs(a - b) * 2
	if a <= d and b <= d and (c <= d):
		if 0 < c + d / 2 <= d:
			l.append(c + d / 2)
		elif 0 < c - d / 2 <= d:
			l.append(c - d / 2)
	else:
		l.append(-1)
for x in l:
	print(int(x))


def compute(a, b, c):
	diff = abs(a - b)
	if max(a, b) > diff * 2 or c > diff * 2:
		return -1
	else:
		a = c + diff
		if c + diff > diff * 2:
			while a > diff * 2:
				a -= diff * 2
		return a
t = int(input())
main_list = []
for i in range(t):
	a = list(map(int, input().split()))
	main_list.append(a)
for i in range(len(main_list)):
	print(compute(main_list[i][0], main_list[i][1], main_list[i][2]))


t = int(input())
u = []
for i in range(t):
	(a, b, c) = map(int, input().split())
	if a > b:
		if (a - b) * 2 >= c and (a - b) * 2 >= a and ((a - b) * 2 >= b):
			if (a - b) * 2 >= c + a - b:
				u.append(c + (a - b))
			else:
				u.append(c - (a - b))
		else:
			u.append(-1)
	elif a < b:
		if (b - a) * 2 >= c and (b - a) * 2 >= a and ((b - a) * 2 >= b):
			if (b - a) * 2 >= c + b - a:
				u.append(c + (b - a))
			else:
				u.append(c - (b - a))
		else:
			u.append(-1)
	else:
		u.append(-1)
for i in range(len(u)):
	print(u[i])


numbers = list()
repeats = int(input())
d = list()
e = list()
f = list()
for i in range(repeats):
	(a, b, c) = list(map(int, input().split()))
	d += [a]
	e += [b]
	f += [c]
for j in range(repeats):
	diff = abs(d[j] - e[j])
	if diff * 2 >= d[j] and diff * 2 >= e[j] and (diff * 2 >= f[j]):
		if diff < f[j]:
			print(f[j] - diff)
		else:
			print(f[j] + diff)
	else:
		print(-1)


import math
t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	n = abs(b - a) * 2
	diff = abs(b - a)
	if a > n or b > n or c > n:
		print(-1)
		continue
	(x1, x2) = (c + diff, c - diff)
	ans = -1
	if 1 <= x1 <= n:
		ans = c + diff
	if 1 <= x2 <= n:
		ans = c - diff
	print(ans)


test = int(input())
li = abc = []
for i in range(test):
	li = list(map(int, input().split()))
	abc.append(li)
for i in range(test):
	ans = -1
	(a, b, c) = (abc[i][0], abc[i][1], abc[i][2])
	n = 2 * abs(a - b)
	if n >= a > 0 and n >= b > 0 and (n >= c > 0):
		if c <= n // 2:
			ans = c + n // 2
		else:
			ans = c - n // 2
	print(ans)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	g = abs(b - a)
	n = 2 * g
	if a > n or b > n or c > n:
		print(-1)
	else:
		d = int((c + g) % n)
		if d == 0:
			d = n
		print(d)


x = int(input())
for i in range(x):
	(w, y, z) = map(int, input().split())
	if abs(2 * (w - y)) < w or abs(2 * (w - y)) < y or abs(2 * (w - y)) < z:
		print(-1)
	else:
		y = abs(w - y)
		if z > y:
			print(z - y)
		else:
			print(z + y)


qu = []
for _ in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	qu.append([a, b, c])
for q in qu:
	(a, b, c) = q
	if abs(a - b) == 1:
		print(-1)
	else:
		if a > b:
			smaller = b
			bigger = a
		else:
			smaller = a
			bigger = b
		pointer1 = bigger - (smaller - 1)
		if pointer1 > bigger:
			print(-1)
		elif pointer1 <= smaller:
			print(-1)
		else:
			h = pointer1 + abs(a - b) - 1
			pointer_c = c + abs(a - b)
			if pointer_c > h:
				pointer_c = c - abs(a - b)
			if c > h or pointer_c < 1:
				print(-1)
			else:
				print(pointer_c)


from sys import stdin
for i in range(int(stdin.readline())):
	(a, b, c) = list(map(int, stdin.readline().split()))
	(a, b) = sorted([a, b])
	diff = b - a
	if a - diff >= 1 or c - diff >= b or c + diff <= a or (c > 2 * diff):
		print(-1)
		continue
	if c - diff >= 1:
		print(c - diff)
	elif c + diff <= 2 * diff:
		print(c + diff)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	n = int(abs(a - b) * 2)
	if 1 <= a <= n and 1 <= b <= n and (1 <= c <= n):
		d1 = int(n / 2 + c)
		d2 = int(c - n / 2)
		d = [d1, d2]
		if d1 < 1 or d1 > n:
			pass
		else:
			print(d1)
		if d2 < 1 or d2 > n:
			pass
		else:
			print(d2)
	else:
		print('-1')


def f_b(a, b, c):
	node_no = abs(a - b) * 2
	if a <= node_no and b <= node_no and (c <= node_no):
		if c > abs(a - b):
			d = c - abs(a - b)
		else:
			d = c + abs(a - b)
	else:
		d = -1
	return d
for i in range(int(input())):
	(a, b, c) = input().split()
	print(f_b(int(a), int(b), int(c)))


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	if a > b:
		y = a
		a = b
		b = y
	value = b - a
	if b > value * 2:
		print(-1)
		continue
	if c == value + 1:
		print(1)
	elif c > value + 1:
		if c > value * 2:
			print(-1)
			continue
		print(c - value)
	else:
		print(value + c)


t = int(input())
results = []
for i in range(t):
	(a, b, c) = [int(i) for i in input().split(' ')]
	mid = abs(a - b)
	if c > mid * 2 or mid < 2 or mid < min(a, b):
		results.append(-1)
		continue
	if c < mid:
		results.append(mid + c)
	elif c > mid:
		results.append(c - mid)
	else:
		results.append(mid * 2)
[print(i) for i in results]


t = int(input())
A = []
B = []
C = []
for _ in range(t):
	(a, b, c) = list(map(int, input().split(' ')))
	A.append(a)
	B.append(b)
	C.append(c)

def get_opposite(a, b, c):
	diff = abs(a - b)
	circum = 2 * diff
	if a > circum or b > circum:
		return -1
	if circum < c:
		return -1
	if c > diff:
		return c - diff
	return c + diff
for i in range(t):
	print(get_opposite(A[i], B[i], C[i]))


def solution(arr):
	a = arr[0]
	b = arr[1]
	c = arr[2]
	min_no = min(a, b)
	max_no = max(a, b)
	diff = max_no - min_no
	total = diff * 2
	half = total // 2 + 1
	if max_no > total or c > total:
		return -1
	elif c < half:
		return c + diff
	else:
		return c - diff
	return -1
t = int(input())
a = []
for i in range(0, t):
	a.append([None] * 3)
for i in range(0, t):
	temp = input().split(' ')
	for j in range(0, 3):
		a[i][j] = int(temp[j])
for i in range(0, t):
	print(solution(a[i]))


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	(a, b) = sorted([a, b])
	ob = b - a
	if max([a, b, c]) > ob * 2:
		print(-1)
	else:
		print((c + ob - 1) % (2 * ob) + 1)


t = int(input())
lan = []
for _ in range(t):
	(a, b, c) = map(int, input().split())
	max_c = abs((a - b) * 2)
	if a > max_c or b > max_c:
		lan.append(-1)
	elif c > max_c:
		lan.append(-1)
	elif abs(a - b) == 1:
		lan.append(-1)
	else:
		if c + abs(a - b) <= max_c:
			ans = c + abs(a - b)
		else:
			ans = c - abs(a - b)
		lan.append(ans)
print(*lan, sep='\n')


t = int(input())
for i in range(t):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	if a >= b:
		dia = a - b
	else:
		dia = b - a
	if dia * 2 < c or dia * 2 < a or dia * 2 < b:
		print(-1)
	elif c + dia > 2 * dia:
		print(c - dia)
	else:
		print(c + dia)


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split())
	if a > b:
		k = a
		a = b
		b = k
	n = (b - a) * 2
	if a > n or b > n or c > n:
		print('-1')
	else:
		print((c - 1 + (b - a) + n) % n + 1)


x = int(input())
i = 0
list1 = []
while i < x:
	(a, b, c) = map(int, input().split())
	if a > b:
		t = a - b
	else:
		t = b - a
	tot = 2 * t
	if c > tot or tot < a or tot < b or (t == 1):
		list1.append('-1')
	elif c > t:
		h = c - t
		list1.append(h)
	else:
		h = c + t
		list1.append(h)
	i += 1
for d in list1:
	print(d)


import sys
INF = float('inf')
MOD = 10 ** 9 + 7
MOD2 = 998244353

def main():

	def II():
		return int(sys.stdin.readline())

	def LI():
		return list(map(int, sys.stdin.readline().split()))

	def LC():
		return list(input())

	def IC():
		return [int(c) for c in input()]

	def MI():
		return map(int, sys.stdin.readline().split())
	T = II()
	for _ in range(T):
		(A, B, C) = MI()
		N = abs(A - B)
		All = N * 2
		if not 1 <= A <= All:
			print(-1)
			continue
		if not 1 <= B <= All:
			print(-1)
			continue
		if 1 <= C <= All:
			if C <= N:
				print(C + N)
				continue
			else:
				print(C - N)
		else:
			print(-1)
			continue
main()


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	t = max(a, b) - min(a, b)
	x = 2 * t
	if c > x or a > x or b > x:
		print(-1)
	elif c > t:
		print(c - t)
	else:
		print(c + t)


t = int(input())
lst = []
for i in range(t):
	(a, b, c) = map(int, input().split(' '))
	x = abs(a - b)
	n = 2 * x
	y = c + x
	if c > n or a > n or b > n or (y == a) or (y == b):
		lst.append(-1)
	elif y > n:
		lst.append(abs(c - x))
	else:
		lst.append(y)
for i in lst:
	print(i)


t = int(input())
ans = [0 for _ in range(t)]
for i in range(t):
	(a, b, c) = list(map(int, input().strip().split()))
	total = 2 * abs(a - b)
	diff = abs(a - b)
	if diff <= 1 or a > total or b > total or (c > total):
		ans[i] = -1
		continue
	d1 = c + diff
	d2 = c - diff
	if 1 <= d1 <= total:
		ans[i] = d1
		continue
	if 1 <= d2 <= total:
		ans[i] = d2
		continue
	ans[i] = -1
print('\n'.join([str(ans[i]) for i in range(t)]))


t = int(input())

def solve():
	(a, b, c) = map(int, input().split())
	diff = abs(a - b)
	circleLen = diff * 2
	if a > circleLen or b > circleLen:
		print(-1)
		return
	if c > circleLen:
		print(-1)
		return
	if c + diff <= circleLen:
		print(c + diff)
	elif c - diff > 0:
		print(c - diff)
	else:
		print(-1)
for i in range(t):
	solve()


import os
import math
import sys
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')

def func(a, b, c):
	d = abs(a - b)
	n = 2 * d
	if c > n:
		return -1
	elif a > n or b > n:
		return -1
	else:
		return c + d if c + d <= n else c - d

def main():
	n_cases = int(parse_input())
	for i in range(n_cases):
		(a, b, c) = [int(i) for i in parse_input().split()]
		print(func(a, b, c))
main()


a = int(input())
mas = []
for i in range(a):
	mas.append(input().split())
	mas[i][0] = int(mas[i][0])
	mas[i][1] = int(mas[i][1])
	mas[i][2] = int(mas[i][2])
for i in mas:
	raz = abs(i[0] - i[1])
	le = 2 * raz
	if (i[2] + raz <= le or i[2] - raz >= 1) and (i[0] <= le and i[1] <= le and (i[2] <= le)):
		if i[2] + raz <= le:
			print(i[2] + raz)
		else:
			print(i[2] - raz)
	else:
		print(-1)


aga = int(input())
for i in range(aga):
	s = input()
	arr = s.split()
	a = int(arr[0])
	b = int(arr[1])
	c = int(arr[2])
	dif = abs(a - b)
	if (1 + dif == a or 1 + dif == b) and a != 1 and (b != 1):
		print(-1)
		continue
	if dif < a and dif < b:
		print(-1)
		continue
	if c <= 2 * dif and c + dif != a and (c + dif != b):
		if c + dif <= 2 * dif:
			print(c + dif)
		else:
			print(c - dif)
	else:
		print(-1)


from sys import stdin
from collections import defaultdict
from bisect import insort, bisect_left
for _ in range(int(stdin.readline())):
	(a, b, c) = map(int, stdin.readline().split())
	if a > b:
		(a, b) = (b, a)
	diff = b - a
	max_val = 2 * diff
	if a > max_val or b > max_val or c > max_val:
		print(-1)
		continue
	if c > diff:
		print(c - diff)
	else:
		print(c + diff)


tt = int(input())
while tt > 0:
	tt -= 1
	(a, b, c) = map(int, input().split())
	a -= 1
	b -= 1
	c -= 1
	dist = abs(b - a)
	if max(a, b) >= 2 * dist:
		print(-1)
	elif c >= 2 * dist:
		print(-1)
	else:
		print((c + dist) % (2 * dist) + 1)


import sys
res = []
t = int(sys.stdin.readline())
for _ in range(t):
	(a, b, c) = map(int, sys.stdin.readline().split())
	df = abs(a - b)
	tn = df * 2
	mid = tn // 2 + 1
	if a > tn or b > tn or c > tn:
		print(-1)
		continue
	if a >= 1 and a < mid:
		bs = a + df
		if bs != b:
			print(-1)
			continue
	else:
		bs = a - df
		if bs != b:
			print(-1)
			continue
	if c >= 1 and c < mid:
		d = c + df
		if d > tn:
			print(-1)
			continue
		print(d)
	else:
		d = c - df
		if d < 1:
			print(-1)
			continue
		print(d)


import sys
input = sys.stdin.readline
output = sys.stdout.write

def main():
	tests = int(input().rstrip())
	for i in range(tests):
		(a, b, c) = map(int, input().rstrip().split())
		dif = abs(a - b)
		max_ = dif * 2
		if a > max_ or b > max_ or c > max_:
			ans = -1
		elif c > dif:
			ans = c - dif
		else:
			ans = c + dif
		output(str(ans))
		output('\n')
main()


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(0, t):
	arr = inlt()
	b = max(arr[0], arr[1])
	l = min(arr[0], arr[1])
	if math.floor(b / 2) >= l:
		d = abs(arr[0] - arr[1])
		mid = 1 + d
		if arr[2] <= 2 * d:
			if arr[2] >= mid:
				print(arr[2] - d)
			else:
				print(arr[2] + d)
		else:
			print(-1)
	else:
		print(-1)


def solve():
	(a, b, c) = map(int, input().split())
	n = abs(b - a) * 2
	if n < b or n < a or n < c:
		print(-1)
	else:
		print((c + n // 2 - 1) % n + 1)
t = int(input())
for _ in range(t):
	solve()


import sys
for _ in range(int(sys.stdin.readline())):
	(a, b, c) = map(int, sys.stdin.readline().split())
	diff = abs(a - b)
	if c > diff * 2 or a > diff * 2 or b > diff * 2:
		print(-1)
		continue
	(case1, case2) = (c - diff, c + diff)
	if 1 <= case1 <= diff * 2:
		print(case1)
	elif 1 <= case2 <= diff * 2:
		print(case2)
	else:
		print(-1)


def numbers(arr):
	for l in arr:
		n = 2 * abs(l[0] - l[1])
		if n < l[0] or n < l[1] or n < l[2]:
			print(-1)
		else:
			d = l[2] + abs(l[0] - l[1])
			while d > n:
				d -= n
			print(d)
l = int(input())
arr = []
for i in range(l):
	arr.append([int(j) for j in input().split()])
numbers(arr)


def checkpallidrome(i):
	if i[0::1] == i[-1::-1]:
		return True
	else:
		return False

def uniquebid(l):
	d = {}
	m = 10000
	index = 0
	for i in range(len(l)):
		d[l[i]] = d.get(l[i], 0) + 1
	for i in range(len(l)):
		if m > l[i] and d[l[i]] == 1:
			m = l[i]
			index = i + 1
	if index != 0:
		return index
	return -1

def remove_zero(n):
	while n % 10 == 0:
		n = n / 10
	return int(n)

def count_digit(n):
	co = 0
	while n > 0:
		co = co + 1
		n = n // 10
	return co

def most_frequent(List):
	return max(set(List), key=List.count)

def last_digit(no):
	a = no % 10
	return a

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
c = int(input())
for j in range(c):
	(a, b, c) = map(int, input().strip().split())
	n = 2 * abs(a - b)
	d = c + n // 2 if c + n // 2 <= n else c - n // 2
	if a <= n and b <= n and (c <= n):
		print(d)
	else:
		print('-1')


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	k = abs(a - b) - 1
	d = k * 2 + 2
	if d > 0 and a <= d and (b <= d) and (c <= d):
		ans = c + k + 1
		ans1 = c - k - 1
		if ans <= d and ans != a and (ans != b) and (ans != c):
			print(ans)
		elif ans1 >= 1 and ans != a and (ans != b) and (ans != c):
			print(ans1)
		else:
			print(-1)
	else:
		print(-1)


def spliter():
	d = input()
	a = d.split()
	r = []
	for i in a:
		k = int(i)
		r.append(k)
	return r
n = int(input())
for _ in range(n):
	k = spliter()
	if k[0] > k[1]:
		(k[0], k[1]) = (k[1], k[0])
	if k[0] > k[1] - k[0]:
		print(-1)
	elif k[2] > 2 * (k[1] - k[0]):
		print(-1)
	elif k[2] > k[1]:
		print(k[2] - k[1] + k[0])
	elif k[2] > k[1] - k[0]:
		print(k[2] - k[1] + k[0])
	else:
		print(k[2] + k[1] - k[0])


t = int(input())
l = []
for i in range(0, t):
	m = [int(x) for x in input().split()]
	l.append(m)
for j in range(0, t):
	a = l[j][0]
	b = l[j][1]
	c = l[j][2]
	parts = abs(a - b) * 2
	if a > parts or b > parts or c > parts:
		print(-1)
	else:
		q = abs(b - a) + c
		if q > parts:
			print(abs(abs(a - b) - c))
		else:
			print(q)


for t in range(int(input())):
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	c = l[2]
	if c == 1 and abs(b - a) == 1:
		print(-1)
		continue
	num = abs((b - a) * 2)
	if c > num or max(a, b) > num:
		print(-1)
	elif c <= num // 2:
		print(c + num // 2)
	else:
		print(c - num // 2)


from sys import stdin
input = lambda : stdin.readline().strip()
linput = lambda : [*map(int, input().split())]
output = []

def lprint(*x):
	output.append(' '.join(map(str, x)))

def main():
	(a, b, c) = linput()
	if a > b:
		(a, b) = (b, a)
	r = b - a
	n = r * 2
	if a > n or b > n or c > n:
		lprint(-1)
		return
	if c + r <= n:
		lprint(c + r)
	else:
		lprint(r - n + c)
for _ in ' ' * int(input()):
	main()
print(*output, sep='\n')


t = int(input())
for _ in range(t):
	(a, b, c) = map(int, input().split(' '))
	tn = 2 * abs(a - b)
	if c > tn or a > tn or b > tn:
		print(-1)
	else:
		d = c - tn // 2
		d2 = c + tn // 2
		if d > 0 and d < tn and (d != a) and (d != b):
			print(d)
		elif d2 > 0 and d < tn and (d2 != a) and (d2 != b):
			print(d2)
		else:
			print(-1)


import sys

def rall():
	return sys.stdin.readlines()

def rl():
	return sys.stdin.readline().strip()

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array):
	return array
NT = int(rl())
for ti in range(NT):
	(a, b, c) = [int(x) for x in rl().split(' ')]
	n = 2 * abs(b - a)
	opp = c + n // 2 if c <= n // 2 else c - n // 2
	if c > n:
		opp = -1
	elif a > n or b > n:
		opp = -1
	elif opp <= 0 or opp > n:
		opp = -1
	pr(opp)


t = int(input())
for i in range(t):
	(a, b, c) = input().split()
	(a, b, c) = (int(a), int(b), int(c))
	d = -1
	dif = abs(a - b)
	limit = 2 * dif
	if limit < max(a, b) or c > limit:
		print(d)
		continue
	elif c + dif <= limit:
		d = c + dif
	elif c - dif > 0:
		d = c - dif
	print(d)


import sys
sys.setrecursionlimit(5000001)
from collections import *
from math import *
TT = int(input())
for y in range(TT):
	(n, m, k) = map(int, input().split())
	(a, b) = (max(n, m), min(n, m))
	t = 2 * (a - b)
	if n > t or m > t or k > t:
		print('-1')
	elif k > a - b:
		print((k + (a - b)) % t)
	else:
		print(k + (a - b))


import math
from collections import Counter, deque, defaultdict
MOD = 10 ** 9 + 7
T = int(input())
for _ in range(T):
	(a, b, c) = [int(x) for x in input().split()]
	k = 2 * (max(a, b) - min(a, b))
	if a > k or b > k or c > k:
		print(-1)
	else:
		print((c + abs(a - b) - 1) % k + 1)


t = int(input())
for i in range(t):
	inputList = input().split()
	a = int(inputList[0])
	b = int(inputList[1])
	c = int(inputList[2])
	total = 2 * abs(a - b)
	if c > total or abs(a - b) == 1 or min(a, b) > abs(b - a):
		print(-1)
	elif c + abs(a - b) > total:
		print(c - abs(a - b))
	else:
		print(c + abs(a - b))


import sys
import os
import math
from io import BytesIO, IOBase
from collections import defaultdict, Counter, deque
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	dist = b - a
	ma = 2 * dist
	if max(a, b, c) > ma:
		print(-1)
		continue
	ans = c + dist
	if ans > ma:
		ans = c - dist
	print(ans)


for s in [*open(0)][1:]:
	(a, b, c) = map(int, s.split())
	d = abs(a - b)
	print((c + d, c - d, -1)[min(2, -1 - -c // d)] if a <= 2 * d >= b else -1)


n = []
for i in range(int(input())):
	x = list(map(int, input().split()))
	n.append(x)
for e in n:
	m = 2 * abs(e[0] - e[1])
	if e[0] > m or e[1] > m or e[2] > m:
		print(-1)
	else:
		o = e[2] + m // 2
		if o > m:
			o -= m
		print(o)


t = int(input())
list1 = []
list2 = []
for i in range(t):
	flag = True
	data0 = input()
	list1 = data0.split()
	data = [int(x) for x in list1]
	total = abs(data[0] - data[1]) * 2
	for m in range(3):
		if data[m] > total:
			list2.append(-1)
			flag = False
			break
	if flag:
		result = (max(data[0], data[1]) + (data[2] - min(data[0], data[1])) - 1) % total + 1
		list2.append(result)
for i in range(t):
	print(list2[i])


t = int(input())
r = [0] * t
for i in range(t):
	(a, b, c) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	n = 2 * a - 2 * b
	if c > n or a > n or b > n:
		r[i] = -1
	else:
		r[i] = (c + n // 2) % n
		if r[i] == 0:
			r[i] = n
for i in r:
	print(i)


n = int(input())
x = 0
while x < n:
	(a, b, c) = map(int, input().split(' '))
	t = a - b
	if t < 0:
		t = -t
	if 2 * t < c or 2 * t < a or 2 * t < b:
		print(-1)
	else:
		ans = (c + t) % (2 * t)
		if ans == 0:
			print(ans + 2 * t)
		else:
			print(ans)
	x = x + 1


import math
t = int(input())
for i in range(t):
	(a, b, c) = [int(x) for x in input().split()]
	nop = (abs(a - b) - 1) * 2 + 2
	if a > nop or b > nop or c > nop:
		print(-1)
	else:
		print((a - 1 - (b - c)) % nop + 1)


import sys
t = int(input())
for _ in range(t):
	opposite = 0
	(a, b, c) = map(int, sys.stdin.readline().split())
	place = 2 * abs(a - b)
	if a > place or b > place or c > place:
		print(-1)
	else:
		opposite = c + place // 2
		if opposite > place:
			opposite = c - place // 2
		print(opposite)


q = int(input())
while q != 0:
	(a, b, c) = map(int, input().split())
	if a > b:
		x = a
		a = b
		b = x
	if b - a >= a and c <= 2 * (b - a):
		if c <= b - a:
			print(b - a + c)
		else:
			print(c - (b - a))
	else:
		print(-1)
	q -= 1


t = int(input())
lis = []
out = []
for i in range(t):
	lis.append([int(j) for j in input().split()])
	(a, b, c) = lis[i]
	N = 2 * abs(a - b)
	if c > N or a > N or b > N:
		out.append(-1)
	else:
		d = max(c + N // 2, c - N // 2)
		if d > N:
			d = d % N
		out.append(d)
for i in out:
	print(i)


t = int(input())
for i in range(0, t):
	(a, b, c) = map(int, input().split())
	d = abs(a - b)
	if 2 * d < c or 2 * d < a or 2 * d < b:
		print('-1')
	elif c + d > 2 * d:
		print((c + d) % (2 * d))
	else:
		print(c + d)


def circle(a, b, c):
	m1 = max(a, b)
	m2 = min(a, b)
	n = 2 * (m1 - m2)
	if n < m1 or c > n:
		return -1
	elif c > n // 2:
		return c - n // 2
	else:
		return n // 2 + c
t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	print(circle(a, b, c))


test = int(input())
for i in range(test):
	(a, b, c) = map(int, input().split())
	n = 2 * (a - b)
	diff = a - b
	if n < 0:
		n = -n
	if diff < 0:
		diff = -diff
	if c > n or a > n or b > n:
		print(-1)
	elif c <= n / 2:
		print(int(n / 2) + c)
	else:
		print(c - int(n / 2))