#include using namespace std; typedef long long ll; const int maxn=2e5+100; const int mod = 1e9+7; ll a[1005]; ll quickpow(ll a, ll b) { if (b < 0) return 0; ll ret = 1; a %= mod; while(b) { if (b & 1) ret = (ret * a) % mod; b >>= 1; a = (a * a) % mod; } return ret; } ll inv(ll a) { return quickpow(a, mod - 2); } int main() { int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); ll ans=a[1]/2; for(int i=2;i<=n;i++){ ll x,y; y=a[i]*a[i-1]; x=abs(a[i]-a[i-1]); x*=max(a[i],a[i-1])/2; x*=min(a[i],a[i-1])/2; x%=mod; ans+=x*inv(y); ans%=mod; } printf("%lld\n",ans); } return 0; }