#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb   push_back
#define T int time;        scanf("%d", &time); while(time--)

  int main(){
    ll sum = 0;
      T{
          ll a , b  ;
          cin >> a >> b ;
          sum+=(b*(b+1)/2 - (a*(a-1))/2) ;
         }
         cout << sum << endl ;

      }
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
template <class T> void chmin(T &a, const T &b) {
    if (a > b) a = b;
}
template <class T> void chmax(T &a, const T &b) {
    if (a < b) a = b;
}

void add(ll &a, ll b) {
    a = (a + b) % MOD;
}

void mul(ll &a, ll b) {
    a %= MOD;
    b %= MOD;
    a = a * b % MOD;
}

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> num_dp(2, 0);
    num_dp[0] = 1;
    vector<ll> sum_dp(2, 0);
    sum_dp[0] = A[0];
    for (int i = 1; i < N; i++) {
        vector<ll> nex_num_dp(2, 0);
        vector<ll> nex_sum_dp(2, 0);
        {
            add(nex_num_dp[1], num_dp[0]);
            add(nex_num_dp[0], num_dp[0]);
            add(nex_num_dp[0], num_dp[1]);
        }
        {
            add(nex_sum_dp[1], ((sum_dp[0] - A[i] * num_dp[0] % MOD) % MOD + MOD) % MOD);
            add(nex_sum_dp[0], ((sum_dp[0] + A[i] * num_dp[0] % MOD) % MOD + MOD) % MOD);
            add(nex_sum_dp[0], ((sum_dp[1] + A[i] * num_dp[1] % MOD) % MOD + MOD) % MOD);
        }
        swap(nex_num_dp, num_dp);
        swap(nex_sum_dp, sum_dp);
    }

    ll ans = 0;
    add(ans, sum_dp[0]);
    add(ans, sum_dp[1]);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}