#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define LOG(FMT...) fprintf(stderr, FMT) using namespace std; typedef long long ll; typedef unsigned long long ull; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template istream &operator>>(istream &is, vector &v) { for (T &x : v) is >> x; return is; } template ostream &operator<<(ostream &os, const vector &v) { if (!v.empty()) { os << v.front(); for (int i = 1; i < v.size(); ++i) os << ' ' << v[i]; } return os; } const int P = 1000000007; int norm(int x) { return x >= P ? (x - P) : x; } void add(int &x, int y) { if ((x += y) >= P) x -= P; } void sub(int &x, int y) { if ((x -= y) < 0) x += P; } void exGcd(int a, int b, int &x, int &y) { if (!b) { x = 1; y = 0; return; } exGcd(b, a % b, y, x); y -= a / b * x; } int inv(int a) { int x, y; exGcd(a, P, x, y); return norm(x + P); } int main() { #ifdef ELEGIA freopen("test.in", "r", stdin); int nol_cl = clock(); #endif ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; int ans = 0; vector a(n); cin >> a; for (int i = 0; i < n; ++i) add(ans, a[i] / 2); for (int i = 1; i < n; ++i) { int res = norm(inv(a[i - 1]) + inv(a[i])); res = res * (ll) (a[i] / 2 * (ll) a[i - 1] / 2) % P; sub(ans, res); } cout << ans << '\n'; } #ifdef ELEGIA LOG("Time: %dms\n", int ((clock() -nol_cl) / (double)CLOCKS_PER_SEC * 1000)); #endif return 0; }