#include #include #include using namespace std; #define SZ(x) ((int)(x).size()) #define PB(x) push_back(x) #define MEMSET(x,v) memset(x,v,sizeof(x)) #define REP(i,n) for(int (i)=0;(i)<(n);++(i)) #define x first #define y second #define INF (0x3f3f3f3f) typedef long long LL; typedef pair P2; template inline bool mina(A &x, B y) {return (x > y)?(x=y,1):0;} template inline bool maxa(A &x, B y) {return (x < y)?(x=y,1):0;} template class ModInt { public: static const Int Mod = mod; Int x; ModInt() { x = 0; } ModInt(int a) { Int t = a % mod; if(t < 0) t += mod; x = t; } ModInt(long long a) { Int t = a % mod; if(t < 0) t += mod; x = t; } Int get() const { return x; } ModInt &operator += (ModInt that) { if((x += that.x) >= mod) x -= mod; return *this; } ModInt &operator -= (ModInt that) { if((x += mod - that.x) >= mod) x -= mod; return *this; } ModInt &operator *= (ModInt that) { x = (long long)(x) * that.x % mod; return *this; } bool operator == (ModInt that) const { return x == that.x; } ModInt operator + (ModInt that) const { return ModInt(*this) += that; } ModInt operator - (ModInt that) const { return ModInt(*this) -= that; } ModInt operator * (ModInt that) const { return ModInt(*this) *= that; } ModInt operator - () const { return ModInt(-this->x); } inline friend ostream& operator << (ostream &out, ModInt m) {return out << m.x;} ModInt power(long long k) const { ModInt r(1); ModInt b = *this; if (k <= 0) return r; while (k) { if (k & 1) r *= b; b *= b; k >>= 1; } return r; } ModInt inverse() const { long long a = x, b = mod, u = 1, v = 0; while(b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return ModInt(u); } }; #define MOD (100000007) typedef ModInt Mint; const int MAXN = 1005; Mint cnt[MAXN]; Mint temp[MAXN]; int N; int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } int ggg[MAXN][MAXN]; void solve() { REP(i, MAXN) cnt[i] = 0; REP(i, MAXN) temp[i] = 0; scanf("%d", &N); int a; REP(i, N) { scanf("%d", &a); REP(j, MAXN) { temp[j] = cnt[j]; } temp[a] = temp[a] + 1; REP(j, MAXN) { if (cnt[j].get()) { temp[ggg[j][a]] += cnt[j]; } } REP(j, MAXN) cnt[j] = temp[j]; } Mint ans = 0; REP(i, MAXN) ans += cnt[i] * i; cout << ans.get() << endl; } int main() { for (int i = 1; i < MAXN; i++) { for (int j = 1; j <= i; j++) { ggg[i][j] = ggg[j][i] = gcd(i, j); } } int test; scanf("%d", &test); REP(tt, test) { solve(); } return 0; }