#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long pow_mod(long long base, long long exp) {
long long result = 1;
base %= MOD;
while (exp > 0) {
if (exp % 2 == 1) {
result = (result * base) % MOD;
}
base = (base * base) % MOD;
exp /= 2;
}
return result;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
unordered_map<int, int> freq;
for (int i = 0; i < n; ++i) {
cin >> a[i];
freq[a[i]]++;
}
int mex = 0;
while (freq.count(mex)) {
mex++;
}
sort(a.begin(), a.end());
vector<long long> left_product(mex + 1);
left_product[0] = 1;
for (int y = 0; y < mex; ++y) {
int cnt = freq[y];
long long term = (pow_mod(2, cnt) - 1 + MOD) % MOD;
left_product[y + 1] = (left_product[y] * term) % MOD;
}
long long sum = 0;
for (int x = 1; x <= mex; ++x) {
int sum_leq_x = upper_bound(a.begin(), a.end(), x) - a.begin();
int sum_gt_x = n - sum_leq_x;
long long right_pow = pow_mod(2, sum_gt_x);
long long count_x = (left_product[x] * right_pow) % MOD;
sum = (sum + x * count_x) % MOD;
}
cout << sum % MOD << '\n';
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTU9EID0gMWU5ICsgNzsKCmxvbmcgbG9uZyBwb3dfbW9kKGxvbmcgbG9uZyBiYXNlLCBsb25nIGxvbmcgZXhwKSB7CiAgICBsb25nIGxvbmcgcmVzdWx0ID0gMTsKICAgIGJhc2UgJT0gTU9EOwogICAgd2hpbGUgKGV4cCA+IDApIHsKICAgICAgICBpZiAoZXhwICUgMiA9PSAxKSB7CiAgICAgICAgICAgIHJlc3VsdCA9IChyZXN1bHQgKiBiYXNlKSAlIE1PRDsKICAgICAgICB9CiAgICAgICAgYmFzZSA9IChiYXNlICogYmFzZSkgJSBNT0Q7CiAgICAgICAgZXhwIC89IDI7CiAgICB9CiAgICByZXR1cm4gcmVzdWx0Owp9CgppbnQgbWFpbigpIHsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUobnVsbHB0cik7CiAgICAKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSB7CiAgICAgICAgaW50IG47CiAgICAgICAgY2luID4+IG47CiAgICAgICAgdmVjdG9yPGludD4gYShuKTsKICAgICAgICB1bm9yZGVyZWRfbWFwPGludCwgaW50PiBmcmVxOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgICAgIGNpbiA+PiBhW2ldOwogICAgICAgICAgICBmcmVxW2FbaV1dKys7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIGludCBtZXggPSAwOwogICAgICAgIHdoaWxlIChmcmVxLmNvdW50KG1leCkpIHsKICAgICAgICAgICAgbWV4Kys7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHNvcnQoYS5iZWdpbigpLCBhLmVuZCgpKTsKICAgICAgICAKICAgICAgICB2ZWN0b3I8bG9uZyBsb25nPiBsZWZ0X3Byb2R1Y3QobWV4ICsgMSk7CiAgICAgICAgbGVmdF9wcm9kdWN0WzBdID0gMTsKICAgICAgICBmb3IgKGludCB5ID0gMDsgeSA8IG1leDsgKyt5KSB7CiAgICAgICAgICAgIGludCBjbnQgPSBmcmVxW3ldOwogICAgICAgICAgICBsb25nIGxvbmcgdGVybSA9IChwb3dfbW9kKDIsIGNudCkgLSAxICsgTU9EKSAlIE1PRDsKICAgICAgICAgICAgbGVmdF9wcm9kdWN0W3kgKyAxXSA9IChsZWZ0X3Byb2R1Y3RbeV0gKiB0ZXJtKSAlIE1PRDsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgbG9uZyBsb25nIHN1bSA9IDA7CiAgICAgICAgZm9yIChpbnQgeCA9IDE7IHggPD0gbWV4OyArK3gpIHsKICAgICAgICAgICAgaW50IHN1bV9sZXFfeCA9IHVwcGVyX2JvdW5kKGEuYmVnaW4oKSwgYS5lbmQoKSwgeCkgLSBhLmJlZ2luKCk7CiAgICAgICAgICAgIGludCBzdW1fZ3RfeCA9IG4gLSBzdW1fbGVxX3g7CiAgICAgICAgICAgIGxvbmcgbG9uZyByaWdodF9wb3cgPSBwb3dfbW9kKDIsIHN1bV9ndF94KTsKICAgICAgICAgICAgbG9uZyBsb25nIGNvdW50X3ggPSAobGVmdF9wcm9kdWN0W3hdICogcmlnaHRfcG93KSAlIE1PRDsKICAgICAgICAgICAgc3VtID0gKHN1bSArIHggKiBjb3VudF94KSAlIE1PRDsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgY291dCA8PCBzdW0gJSBNT0QgPDwgJ1xuJzsKICAgIH0KICAgIAogICAgcmV0dXJuIDA7Cn0=