#include using namespace std; typedef long long ll; typedef pair pii; #define sz(a) ((int)a.size()) #define pb push_back #define lson (rt << 1) #define rson (rt << 1 | 1) #define gmid (l + r >> 1) const int maxn = 5e2 + 5; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int a[maxn]; int n; int main(){ ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--){ int inv2 = (mod + 1) / 2; cin >> n; for(int i = 1; i <= n; ++i){ cin >> a[i]; } int ret = (a[1] + a[n]) / 2 * 1ll * inv2 % mod; cout << ret << "\n"; } return 0; }