import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); sb.append(getCount(a, b, c)).append("\n"); } System.out.print(sb); } static int getCount(int a, int b, int c) { int min = Integer.MAX_VALUE; min = Math.min(min, getOrderCount(a, c, b)); min = Math.min(min, getOrderCount(c, a, b)); min = Math.min(min, getOrderCount(b, a, c)); min = Math.min(min, getOrderCount(b, c, a)); if (min == Integer.MAX_VALUE) { return -1; } else { return min; } } static int getOrderCount(int a, int b, int c) { int count = 0; if (a <= b) { count += b - a + 1; b = a - 1; } if (b <= c) { count += c - b + 1; c = b - 1; } if (c <= 0) { return Integer.MAX_VALUE; } else { return count; } } }