#include<bits/stdc++.h>   using namespace std;   void solve();   int main()   {    ios_base::sync_with_stdio(false); cin.tie(NULL);      #ifndef ONLINE_JUDGE    freopen( input1.txt ,  r , stdin);    freopen( error1.txt ,  w , stderr);    freopen( output1.txt ,  w , stdout);   #endif       int t ; cin >> t;    while (t--)    {     solve();     cout <<   n ;    }       cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;    return 0;   }   void solve()   {    long long n, x ;    cin >> n >> x ;    long long a[n], b[n], s = 0, s1 = 0, j = 0;    for (long long i = 0; i < n; i++)     cin >> a[i];    for (long long i = 0; i < n; i++)     s += a[i];    for (long long i = 0; i < n; i++)     b[i] = a[i];    while (1) {     if (j >= n)      j = 0;     if (b[j] % x != 0)      break;     s += a[j];     b[j] /= x;     j++;    }    cout << s;   }