#include<bits/stdc++.h> #define re register #define int long long
usingnamespace std;
constint N = 1e5 + 10; int n,arr[N]; int vis[N],sum1[N],sum2[N],dp[N];
inlineintread(){ int r = 0,w = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9'){ r = (r << 3) + (r << 1) + (c ^ 48); c = getchar(); } return r * w; }
inlinevoidsolve(){ memset(dp,0,sizeof(dp)); memset(vis,0,sizeof(vis)); memset(sum1,0,sizeof(sum1)); memset(sum2,0,sizeof(sum2)); int ans = 0; n = read(); for (re int i = 1;i <= n;i++) arr[i] = read(); sort(arr + 1,arr + n + 1); for (re int i = 1;i <= n;i++){ sum1[arr[i]] += (n - i); sum2[arr[i]] += vis[arr[i]] * (n - i); vis[arr[i]]++; } for (re int i = 1;i <= 1e5;i++){ int cnt = 0,res = 0; dp[i] += i; for (re int j = i + i;j <= 1e5;j += i) dp[j] -= dp[i]; for (re int j = i;j <= 1e5;j += i){ res += cnt * sum1[j] + sum2[j]; cnt += vis[j]; } ans += dp[i] * res; } printf("%lld\n",ans); }
signedmain(){ int T; T = read(); while (T--) solve(); return0; }