#include using namespace std; const int P = 1e9 + 7 , iv4 = (P + 1) / 4; int poww(long long a , int b){int tms = 1; while(b){if(b & 1) tms = tms * a % P; a = a * a % P; b >>= 1;} return tms;} int T , N , A[1003]; int main(){ for(cin >> T ; T ; --T){ cin >> N; for(int i = 1 ; i <= N ; ++i) cin >> A[i]; int cnt = A[1] / 2; for(int i = 2 ; i <= N ; ++i) if(A[i] != A[i - 1]) cnt = (cnt + (A[i] - A[i - 1]) * 1ll * iv4) % P; cout << cnt << endl; } return 0; }