include
include
include
using namespace std;
int main()
{
int t;
cin >> t; // Input the number of test cases
while(t--)
{
int n;
cin >> n; // Input the number of chocolates
vector chocolates(n);
for(int i=0; i> chocolates[i]; // Input the number of chocolates in each packet
}
sort(chocolates.begin(), chocolates.end()); // Sort the chocolates in ascending order
int max_chocolates = chocolates[n-1]; // Get the maximum number of chocolates
int min_chocolates = chocolates[0]; // Get the minimum number of chocolates
int ans = max_chocolates - min_chocolates; // Calculate the difference between the maximum and minimum number of chocolates
cout << ans << endl; // Output the result
}
return 0;
}