package main import ( "fmt" "bufio" "os" "strconv" ) //=====I/O===== var ( sc = bufio.NewScanner(os.Stdin) wr = bufio.NewWriter(os.Stdout) ) func scanInt() int { sc.Scan() a,_ := strconv.Atoi(sc.Text()) return a } func scanInt64() int64 { sc.Scan() a,_ := strconv.ParseInt(sc.Text(),10,64) return a } func scanInts(n int) []int { res := make([]int, n) for i := 0; i < n; i++ { res[i] = scanInt() } return res } func scanText() string { sc.Scan() return sc.Text() } func printInts(a ...int) { for i, e := range a { fmt.Fprint(wr, e) if i != len(a)-1 { fmt.Fprint(wr, " ") } } fmt.Fprintln(wr) wr.Flush() } //=====main===== func main() { sc.Split(bufio.ScanWords) t := scanInt() for i := 0; i < t; i++ { a,b,c := scanInt(), scanInt(), scanInt() f := 0 if a==c { f++ c-- } if c<1 { fmt.Println(-1) continue } val := -1 if b>2 { val1 := 0 if a-b >= 0 { val1 = a-b+1 } if c-b >= 0 { val1+=c-b+1 } if a-b >= 0&&c-b >= 0 { val++ } val = val1 } if min(a,c)>1 { val2 := max(max(b-a,0),max(b-c,0))+1 val = min(val,val2) } fmt.Println(f+val) } } func abs(a int) int { if a<0 { return -a } return a } func min(a ...int) int { res := a[0] for i := 1; i < len(a); i++ { if res > a[i] { res = a[i] } } return res } func max(a ...int) int { res := a[0] for i := 1; i < len(a); i++ { if res < a[i] { res = a[i] } } return res }