/*        समस्या का समाधान पंक्ति 119 से शुरू होता है|    */
#include<bits/stdc++.h>
using namespace std;
#define hi ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
typedef long double ld;
typedef long long unsigned llu;
#define test                int test; cin>>test; while(test--)
#define loop(i,n,k)         for(int i=n;i<k;i++)
#define rloop(i,n,k)         for(int i=n;i>=k;i--)
#define pb(i)                 push_back(i)
#define sz(i)                 i.size()
#define mkp(i,j)            make_pair(i,j)
#define ip                     pair<int,int>
#define lp                    pair<ll,ll>
#define FOR(i,n)            for(i=0;i<n;i++)
#define range(v)            v.begin(),v.end()
#define bye                    return 0;
#define file                freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define endl                 '\n'
#define ff                     first
#define ss                  second
#define vi                     vector<int>  
#define vll                  vector<ll>           
#define vd                  vector<double> 
#define vs                     vector<string>         
#define vip                 vector<ip>
#define vlp                 vector<lp>
#define vvi                    vector<vi>
#define vvl                 vector<vll>
#define vs                    vector<string>
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(llu t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

template<class c>
c lcm(c a,c b){
    return a/gcd(a,b)*b;
}
template<class a>
bool prime(a n){
    for(a i=2;i<=sqrt(n);i++){
        if(n%i==0)
            return 0;
    }
    return 1;
}
bool bigger(pair<int,int>picachu,pair<int,int> qicachu){
    return (picachu.first<qicachu.first);
}
template<class a>
void printarr(a arr[],int n){
    for(int i=0;i<n;i++)
        cout<<arr[i]<<' ';
    cout<<endl;
}
template<class c>
void printarr(vector<c> v){
    for(auto i:v){
        cout << i << ' ';
    }
    cout << endl;
}
template<class c>
void printarr(set<c> s){
    for(auto i:s){
        cout << i << ' ';
    }
    cout << endl;
}
int chartoint(char c) {
    if (c >= 'a' && c <= 'z') return c - 'a';
    if (c >= 'A' && c <= 'Z') return c - 'A' + 26;
    return 52;
}
template<class t>
t extended_gcd(t a,t b,t &x,t &y){
    t x1,y1;
    if(b==0){
        x = 1,y = 0;
        return a; 
    }
    t g = extended_gcd(b,a%b,x1,y1);
    x = y1;
    y = x1-(a/b)*y1;
    return g;
}
template<class a>
a powmod(a t1,a t2, a mod){
    a res = 1;
    t1 = t1%mod;
    if(t1==0)    return 0;
    while(t2){
        if(t2&1) res = (res*t1)%mod;
        t1 = (t1*t1)%mod;
        t2 = t2>>1;
    }
    return res;
}
/*==============================================================================================
                        टेम्पलेट यहाँ समाप्त होता है
==============================================================================================*/
const ll MOD = 1e9+7;
const int N = 1e5;
void run(){    
    ll n;
    cin >> n;
    vll a(n);
    loop(i,0,n){
        cin >> a[i];
    }
    ll ans  = 0;
    loop(i,0,n){
        ll m;
        if(i==0){
            m = a[i+1];
        }else if(i==n-1){
            m = a[i-1];
        }else{
            m = max(a[i+1],a[i-1]);
        }
        if(a[i]>m){
            ans += a[i]-m;
            a[i] = m;
        }
    }
    debug(a);
    loop(i,0,n){
        if(i==0){
            ans+= a[i];
        }else if(i==n-1){
            ans += a[i];
        }else{
            if(a[i]>a[i-1]) ans += a[i]-a[i-1];
            else if(a[i]>a[i+1])    ans += a[i]-a[i+1];
        }
        debug(ans);
    }
    cout << ans << endl;
}

int main(){
    hi;
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin); 
      freopen("error.txt", "w", stderr); 
      freopen("output.txt", "w", stdout); 
       #endif 
   
      cout << setprecision(15) << fixed;
       test{ 
          run(); 
       }
      cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
     bye;
}