#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <string>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define vs vector<string>
#define v(t) vector<t>
#define mii map<ll, ll>
#define umii unordered_map<ll, ll>
#define si set<ll>
#define usi unordered_set<ll>
#define pq priority_queue<ll>
#define pqs priority_queue<ll, vi, greater<ll>>
#define all(v) v.begin(), v.end()
#define ff first
#define ss second
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define loopr(i, a, b) for (ll i = a; i > b; i--)
#define print(v) for (auto x : v) cout << x << " ";
#define endl "\n"
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define MOD 1000000007
#define PI 3.1415926535897932384626
ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
void solve() {
ll n, x, y, a, a_x, a_y, b_x, b_y, ans = 0;
cin >> n >> x >> y;
map<pair<int, int>, int> count;
loop(i, 0, n) {
cin >> a;
a_x = a % x, a_y = a % y;
if (a_x == 0) b_x = 0; else b_x = x - a_x;
if (a_y == 0) b_y = 0; else b_y = a_y;
ans += count[make_pair(b_x, b_y)];
count[make_pair(a_x, a_y)]++;
}
cout << ans << endl;
}
int main() {
fast
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ll t;
cin >> t;
while (t--) {
solve();
}
// solve();
return 0;
}
1478A - Nezzar and Colorful Balls | 1581B - Diameter of Graph |
404A - Valera and X | 908A - New Year and Counting Cards |
146A - Lucky Ticket | 1594C - Make Them Equal |
1676A - Lucky | 1700B - Palindromic Numbers |
702C - Cellular Network | 1672C - Unequal Array |
1706C - Qpwoeirut And The City | 1697A - Parkway Walk |
1505B - DMCA | 478B - Random Teams |
1705C - Mark and His Unfinished Essay | 1401C - Mere Array |
1613B - Absent Remainder | 1536B - Prinzessin der Verurteilung |
1699B - Almost Ternary Matrix | 1545A - AquaMoon and Strange Sort |
538B - Quasi Binary | 424A - Squats |
1703A - YES or YES | 494A - Treasure |
48B - Land Lot | 835A - Key races |
1622C - Set or Decrease | 1682A - Palindromic Indices |
903C - Boxes Packing | 887A - Div 64 |