#include #include #include #define rep(i, l, r) for(int i=l; i<=r; i++) #define down(i, l, r) for(int i=l; i>=r; i--) #define travel(x) for(edge *p=fir[x]; p; p=p->n) #define clr(x,c) memset(x, c, sizeof(x)) #define ll long long #define pb push_back #define lowbit(x) (x&-x) #define l(x) Left[x] #define r(x) Right[x] #define maxn 1009 #define Q 100000007 using namespace std; inline int read() { int x=0, f=1; char ch=getchar(); while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} while ('0'<=ch && ch<='9') x=x*10+ch-'0', ch=getchar(); return x*f; } int n, f[maxn], k[maxn]; int g[maxn][maxn]; int main() { rep(i, 0, 1000) g[i][0]=g[0][i]=i; rep(a, 1, 1000) rep(b, 1, a) g[b][a]=g[a][b]=g[b][a%b]; int t=read(); while (t--) { n=read(); clr(f,0); rep(i, 1, n) k[i]=read(); sort(k+1, k+1+n); rep(i, 1, n) { rep(a, 1, k[i]) (f[g[a][k[i]]]+=f[a])%=Q; f[k[i]]++; } int ans=0; rep(i, 1, 1000) (ans+=1LL*i*f[i]%Q)%=Q; printf("%d\n", ans); } return 0; }