description: 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.
  
  <image> 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 ≤ t ≤ 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 ≤ a,b,c ≤ 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.
  
  Example
  
  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.
solution: import java.util.*;import java.io.*;import java.math.*;
  public class CF1560B
  {
      static boolean memory = true;
      static long mod = 998244353;
      static long MOD = 1000000007; 
      
      static void ruffleSort(int[] a) {
          int n = a.length;
          ArrayList<Integer> lst = new ArrayList<>();
          for(int i : a)
              lst.add(i);
          Collections.sort(lst);
          for(int i = 0; i < n; i++)
              a[i] = lst.get(i);
      }
  
      static void ruffleSort(long[] a) {
          int n = a.length; 
          ArrayList<Long> lst = new ArrayList<>();
          for(long i : a)
              lst.add(i);
          Collections.sort(lst);
          for(int i = 0; i < n; i++)
              a[i] = lst.get(i);
      }
  
      public static void process()throws IOException
      {
          int p = ni(), q = ni(), c = ni();
          int a = Math.min(p, q);
          int b = Math.max(p, q);
          if(b-a == 1 || a-1 >= b-a){
              pn(-1);
              return;
          }
          int max = (b-a)*2;
          int d = c-(b-a);
          if(d <= 0 || d == a || d == b)
              d = c+(b-a);
          if(c > max || d > max)
              pn(-1);
          else
              pn(d);
      }
     
      static AnotherReader sc;
      static PrintWriter out;
  
      public static void main(String[] args) throws Exception{
          if(memory)new Thread(null, new Runnable() {public void run(){try{new CF1560B().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 32).start();
          else new CF1560B().run();
      }
  
      void run()throws Exception
      {
          boolean oj = System.getProperty("ONLINE_JUDGE") != null;
          if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
          else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
          long s = System.currentTimeMillis();
          int t=1;
          t=ni();
          //int k = t;
          while(t-->0) {/*p("Case #"+ (k-t) + ": ")*/;process();}
          out.flush();
          System.err.println(System.currentTimeMillis()-s+"ms");
          out.close();
      }
  
      static long power(long k, long c, long mod){
          long y = 1;
          while(c > 0){
              if(c%2 == 1)
                  y = y * k % mod;
              c = c/2;
              k = k * k % mod;
          }
          return y;
      }
  
      static int power(int x, int y, int p){ 
          int res = 1;
          x = x % p;
          while (y > 0) {
              if (y % 2 == 1)
                  res = (res * x) % p;
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
  
      static int log2(int N)
      {
          int result = (int)(Math.log(N) / Math.log(2));
          return result;
      }
  
   
      static void pn(Object o){out.println(o);}
      static void pn(int[] a){for(int i : a)out.print(i+" ");pn("");}
      static void pn(long[] a){for(long i : a)out.print(i+" ");pn("");}
      static void p(Object o){out.print(o);}
      static void YES(){out.println("YES");}
      static void NO(){out.println("NO");}
      static void yes(){out.println("yes");}
      static void no(){out.println("no");}
      static void p(int[] a){for(int i : a)out.print(i+" ");}
      static void p(long[] a){for(long i : a)out.print(i+" ");}
      static void pni(Object o){out.println(o);out.flush();}
      static int ni()throws IOException{return sc.nextInt();}
      static long nl()throws IOException{return sc.nextLong();}
      static double nd()throws IOException{return sc.nextDouble();}
      static String nln()throws IOException{return sc.nextLine();}
      static String ns()throws IOException{return sc.next();}
      static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
      static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
      static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
      static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
      static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
      
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
   
      static class AnotherReader{BufferedReader br; StringTokenizer st;
      AnotherReader()throws FileNotFoundException{
      br=new BufferedReader(new InputStreamReader(System.in));}
      AnotherReader(int a)throws FileNotFoundException{
      br = new BufferedReader(new FileReader("input.txt"));}
      String next()throws IOException{
      while (st == null || !st.hasMoreElements()) {try{
      st = new StringTokenizer(br.readLine());}
      catch (IOException  e){ e.printStackTrace(); }}
      return st.nextToken(); } int nextInt() throws IOException{
      return Integer.parseInt(next());}
      long nextLong() throws IOException
      {return Long.parseLong(next());}
      double nextDouble()throws IOException { return Double.parseDouble(next()); }
      String nextLine() throws IOException{ String str = ""; try{
      str = br.readLine();} catch (IOException e){
      e.printStackTrace();} return str;}}
  
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  }