#include<bits/stdc++.h>
using namespace std ;
#define faster() ios::sync_with_stdio(false); cin.tie(nullptr) ; cout.tie(nullptr);
#define endl "\n"
#define int long long
const int MOD = 1e9 + 7 ;
void solve(){
int n , x ; cin >> n >> x ;
vector<int> a(n);
for(int i = 0 ; i < n ; i++) cin >> a[i];
int ans = a[0];
for (int i = 1; i < n; i++){
ans = (ans * x + a[i]);
ans %= MOD ;
}
cout << ans << endl;
}
signed main(){
faster();
int test ;
cin >> test;
while(test--) solve();
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZCA7CiNkZWZpbmUgZmFzdGVyKCkgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOyBjaW4udGllKG51bGxwdHIpIDsgY291dC50aWUobnVsbHB0cik7CiNkZWZpbmUgZW5kbCAiXG4iCiNkZWZpbmUgaW50IGxvbmcgbG9uZwpjb25zdCBpbnQgTU9EID0gMWU5ICsgNyA7Cgp2b2lkIHNvbHZlKCl7CiAgICBpbnQgbiAsIHggOyBjaW4gPj4gbiA+PiB4IDsKICAgIHZlY3RvcjxpbnQ+IGEobik7CiAgICBmb3IoaW50IGkgPSAwIDsgaSA8IG4gOyBpKyspIGNpbiA+PiBhW2ldOwogICAgaW50IGFucyA9IGFbMF07CiAgICBmb3IgKGludCBpID0gMTsgaSA8IG47IGkrKyl7CiAgICAgICAgYW5zID0gKGFucyAqIHggKyBhW2ldKTsKICAgICAgICBhbnMgJT0gTU9EIDsKICAgIH0gICAgICAgCiAgICBjb3V0IDw8IGFucyA8PCBlbmRsOwp9CgpzaWduZWQgbWFpbigpewogICAgZmFzdGVyKCk7CiAgICBpbnQgdGVzdCA7CiAgICBjaW4gPj4gdGVzdDsKICAgIHdoaWxlKHRlc3QtLSkgICBzb2x2ZSgpOwp9