#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll ,ll>
#define pub push_back
using namespace std ;

void get_prime_factors(vector<pll> &prime_factors, ll x)
{
    for(ll i = 2 ; i*i <= x ; i++)
    {
        if(x%i == 0)
        {
            ll cnt = 0 ;
            while(x%i == 0)
            {
                cnt++ ;
                x /= i ;
            }
            prime_factors.pub({i, cnt}) ;
        }
    }

    if(x != 1)
        prime_factors.pub({x , 1}) ;

    return ;
}

void process(vector<vector<ll> > &to_process, vector<pll>& prime_factors, ll &ans)
{
    ll k = prime_factors.size() ;
    map<vector<ll> , ll>  cnt ;
    vector<ll> curr(k) ;

    cnt[curr]++ ;

    for(int i = 0 ; i < to_process.size() ; i++)
    {
        for(int j = 0 ; j < k ; j++)
        {
            curr[j] += to_process[i][j] ;
            curr[j] -= prime_factors[j].second ;
        }
        cnt[curr]++ ;
    }

    for(auto itr = cnt.begin() ; itr != cnt.end() ; itr++)
    {
        ll curr_cnt = (*itr).second ;

        ll curr_ans = ((curr_cnt)*(curr_cnt-1))/2 ;
        ans += curr_ans ;
    }

    return ;
}
    
void solve()
{
    ll n, x ;
    cin >> n >> x ;

    vector<pll> prime_factors ;
    get_prime_factors(prime_factors, x) ;

    ll arr[n] ;
    vector<vector<ll> > to_process ;
    ll ans = 0 ;

    for(int i = 0 ; i < n ; i++)
    {
        cin >> arr[i] ;

        vector<ll> factors ;
        for(int j = 0 ; j < prime_factors.size() ; j++)
        {
            ll p = prime_factors[j].first ;
            ll cnt = 0 ;
            while(arr[i]%p == 0)
            {
                cnt++ ;
                arr[i] /= p ;
            }
            factors.pub(cnt) ;
        }

        if(arr[i] != 1)
        {
            process(to_process, prime_factors, ans) ;
            to_process.clear() ;
        }
        else
        {
            to_process.pub(factors) ;
        }
    }
    process(to_process, prime_factors, ans) ;
    to_process.clear() ;

    cout << ans << endl ;
    return ;

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif

    int t ;
    cin >> t ;
    while(t--)
    {
        solve() ;
    }

    return 0;
}