#include <math.h>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using ull = unsigned long long;
void Code_By_Mohamed_Khaled() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
const ll mod=1e9+7;
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
ll fast_power(ll base,ll power) {
    ll res=1;
    while (power>0) {
        if (power&1)res=mul(res,base);
        base=mul(base,base),power>>=1;
    }
    return res;
}
int main() {
    Code_By_Mohamed_Khaled();
    ll t;cin>>t;
    while (t--) {
        ll n;cin>>n;
        vector<ll>v(n);map<ll,ll>mp;
        for (auto &it:v)cin>>it,mp[it]++;
        if (n==1) {
            cout<<0<<"\n";
            continue;
        }
        // cout<<fast_power(2,mp.size())<<"\n";
        ll ans=add(fast_power(2,mp.size()),mod-1);
        for (auto it:mp) {
            if (it.second>1)ans=mul(ans,it.second-1);
        }
        cout<<add(ans,mod-mp.size())<<"\n";
    }
    return 0;
}