#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; typedef pair PLL; typedef pair PIL; typedef pair PLI; typedef double DB; #define pb push_back #define mset(a, b) memset(a, b, sizeof a) #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define bitl(x) (1LL << (x)) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define cnti(x) (__builtin_popcount(x)) #define cntl(x) (__builtin_popcountll(x)) #define clzi(x) (__builtin_clz(x)) #define clzl(x) (__builtin_clzll(x)) #define ctzi(x) (__builtin_ctz(x)) #define ctzl(x) (__builtin_ctzll(x)) #define X first #define Y second #define Error(x) cout << #x << " = " << x << endl template inline void chkmax(T& x, U y) { if (x < y) x = y; } template inline void chkmin(T& x, U y) { if (y < x) x = y; } const int MOD = 100000007; const int MAXN = 1005; int val[MAXN], cnt[MAXN], f[MAXN], g[MAXN]; int b[MAXN], n; int main() { int ncase; b[0] = 1; for (int i = 1; i < MAXN; i++) b[i] = b[i - 1] * 2 % MOD; for (scanf("%d", &ncase); ncase--;) { scanf("%d", &n); mset(cnt, 0); for (int i = 0; i < n; i++) { int a; scanf("%d", &a); cnt[a]++; } int ans = 0; for (int i = 1000; i >= 1; i--) { int num = 1; int c = 0; for (int j = i; j <= 1000; j += i) num = (LL)num * (cnt[j] + 1) % MOD, c += cnt[j]; val[i] = b[c] - 1; for (int j = 2 * i; j <= 1000; j += i) { val[i] -= val[j]; if (val[i] < 0) val[i] += MOD; } ans = (LL)i * val[i] % MOD + ans; ans %= MOD; } if (ans < 0) ans += MOD; printf("%d\n", ans); } return 0; }