// Arup Guha
// 2/7/2019
// Solution to 2019 Proposed Mercer Problem: Frogs

import java.util.*;

public class frogs_arup {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();
		
		// Go through all cases.
		for (int loop=0; loop<numCases; loop++) {
			
			// Read in and sort locations.
			int n = stdin.nextInt();
			int[] locs = new int[n];
			for (int i=0; i<n; i++)
				locs[i] = stdin.nextInt();
			Arrays.sort(locs);
			
			/*** Here is the logic - after the first jump, we can always leap frog into
			 *   a consecutive position. So, the answer is simply the number of empty slots
			 *   either between position 0 and n-2 or position 1 and n-1, since after the first
			 *   leap each empty position will be hit once. The total number of places between
			 *   index a and index b is b-a+1. From this, we want to subtract out the n-1 frogs
			 *   that are initially located as these spots. So, we just try both intervals and
			 *   take the better answer.
			 ***/
			int res = Math.max(locs[n-2]-locs[0]+1-(n-1), locs[n-1]-locs[1]+1-(n-1));
			System.out.println(res);
		}
	}
}