#include <bits/stdc++.h>
using namespace std;
// Speed
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// Typedefs
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define endl '\n'
#define yes cout << "yes\n"
#define no cout << "no\n"
// Loops
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)
#define each(x, a) for (auto& x : a)
// Consts
const int INF = 1e18;
const int MOD = 1e9+7;
const int N = 2e5 + 5;

void solve() {
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];

    map<pair<int, int>, int> mp;
    int count = 0;

    rep(i, 0, n) {
        int rx = a[i] % x;
        int ry = a[i] % y;
        int rxr = (x - rx) % x;
        int ryr = ry;

        if (mp.count({rxr, ryr})) {
            count += mp[{rxr, ryr}];
        }

        mp[{rx, ry}]++;
    }
    cout << count << endl;
}

int32_t main() {
    fast_io;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}