// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <array>
#include <unordered_set>
#include <cassert>
#include <unordered_map>
#define DEBUG
#define pqueue priority_queue
#define pb(x) push_back(x)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<char> vc;
      
const ll inf = 1e9 + 228;
const ll infll = 1e18;
const ll mod = 1e9 + 7;
//static const int maxn = 1e6 + 228;
const ld eps = 3e-9;
const ll mod2 = 998244353;
const ld PI = atan2l(0, -1);
     
void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen("regions.in", "r", stdin);
//    freopen("regions.out", "w", stdout);
}

void solve(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    for(int &i:a)
        cin >> i;
    vpii kek;
    for(int i=2; i*i<=k; i++){
        if(k % i == 0){
            int cnt = 0;
            while(k % i == 0){
                k/=i;
                ++cnt;
            }
            kek.pb(make_pair(i, cnt));
        }
    }
    if(k > 1){
        kek.pb(make_pair(k, 1));
    }
    map<vector<int>, int> lol;
    vi cur(kek.size(), 0);
    lol[cur]++;
    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<kek.size(); j++){
            int cnt = 0;
            while(a[i] % kek[j].first == 0){
                a[i] /= kek[j].first;
                cnt++;
            }
            cur[j] += cnt - kek[j].second;
        }
        if(a[i] > 1){
            lol.clear();
        }
        ans += lol[cur];
        lol[cur]++;
    }
    cout << ans << endl;
    

}

signed main(){
    fast_io();
    srand(time(NULL));
    cout << fixed << setprecision(12);
    int q = 1;
    cin >> q;
    while(q--)
        solve();
}