#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) cin >> x;
sort(a.begin(), a.end());
cout << a[n - 1] - a[0] << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUgKHQtLSkgewogICAgICAgIGludCBuOwogICAgICAgIGNpbiA+PiBuOwogICAgICAgIHZlY3RvcjxpbnQ+IGEobik7CiAgICAgICAgZm9yIChpbnQgJnggOiBhKSBjaW4gPj4geDsKICAgICAgICBzb3J0KGEuYmVnaW4oKSwgYS5lbmQoKSk7CiAgICAgICAgY291dCA8PCBhW24gLSAxXSAtIGFbMF0gPDwgIlxuIjsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==