#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=3e5;
int main(){
ll t;
cin>>t;
while(t--){
ll n,x,ans=0;
cin>>n;
ll A[N]={0};
ll M[N]={0};
for(ll i=0;i<n;i++){
cin>>x;
A[x]++;
}
for(ll i=1;i<N;i++)
M[i]=M[i-1]+A[i];
for(ll i=1;i<N;i++)
for(ll j=i;j<N;j+=i){
ans+=A[i]*(M[j-1]-M[j-i-1])*(j/i-1);
}
cout<<ans<<"\n";
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgbGwgbG9uZyBsb25nCmNvbnN0IGxsIE49M2U1OwppbnQgbWFpbigpewoKCWxsIHQ7CgljaW4+PnQ7Cgl3aGlsZSh0LS0pewoJbGwgbix4LGFucz0wOwoJY2luPj5uOwoJbGwgQVtOXT17MH07CglsbCBNW05dPXswfTsKCWZvcihsbCBpPTA7aTxuO2krKyl7CgkJY2luPj54OwoJCUFbeF0rKzsKCX0KCglmb3IobGwgaT0xO2k8TjtpKyspCgkJTVtpXT1NW2ktMV0rQVtpXTsKCQoJZm9yKGxsIGk9MTtpPE47aSsrKQoJCWZvcihsbCBqPWk7ajxOO2orPWkpewoJCQlhbnMrPUFbaV0qKE1bai0xXS1NW2otaS0xXSkqKGovaS0xKTsKCQl9Cgljb3V0PDxhbnM8PCJcbiI7Cgl9Cn0KCQoKCg==