/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Code written by Aditya ;)   ||  Codechef/codeforces: @adityaraj5200 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std;

//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update >;

#define fastio                        \
    ios_base::sync_with_stdio(false);   \
    cin.tie(NULL);                      \
    cout.tie(NULL)
#define endl                  "\n" 
#define mod                   1000000007
#define PI                    3.14159265358979323846
#define deb(u)                cout<<'>'<<#u<<" = "<<u<<endl
#define deb2(u, v)            cout<<'>'<<#u<<" = "<<u<<" , "<<#v<<" = "<<v<<endl
#define all(u)                u.begin(), u.end()
#define rall(v)               v.rbegin(), v.rend()
#define sortall(u)            sort(all(u))
#define lcm(a,b)              (a*b)/__gcd(a,b)
#define gcd(a,b)              __gcd(a,b)
#define inclusive(a,b)        (abs(b-a)+1)
#define gap(a,b)              max(0,(abs(b-a)-1))
#define summation(n)          (((n)*(n+1))/2)
#define pb                    push_back
#define ppb                   pop_back
#define pf                    push_front
#define ppf                   pop_front
#define mp                    make_pair
#define lb(u,val)             lower_bound(all(u),val)
#define ub(u,val)             upper_bound(all(u),val)
#define yes                   "YES"
#define no                    "NO"
#define chartoint(ch)         ch-'0'
#define digits(n)             (1+floor(log10(n)))
#define presum(p,a,n)         {int (p)[(n)];p[0]=a[0];for(int i=1;i<(n);i++)p[i]=a[i]+p[i-1];}
#define cube(u)               (u)*(u)*(u)
#define sq(u)                 (u)*(u)
#define fill0(a)              memset(a,0,sizeof(a))
#define fillneg1(a)           memset(a,-1,sizeof(a))
#define fillbig(a)            memset(a,63,sizeof(a))
#define setbits(u)            __builtin_popcount(u)
#define ctz(u)                __builtin_ctz(u)
#define clz(u)                __builtin_clz(u)
#define checkbit(num,i)       (num&(1<<i))  //select the bit of position i of val
#define lowbit(u)             ((u)&((u)^((u)-1))) //get the lowest bit of u
#define trav(u,it)            for(auto it = u.begin(); it != u.end(); it++)
#define present(u,key)        u.find(key) != u.end()
#define notpresent(u,key)     u.find(key) == u.end()
#define in(u, a, b)           (a <= u && u <= b)
#define print(u)              for(auto it=u.begin();it!=u.end();it++)\
                        cout<<*it<<' '; cout<<endl
#define printii(u)            for(auto it=u.begin();it!=u.end();it++)\
                        cout<<it->first<<' '<<it->second<<endl

typedef unsigned int          uint;
typedef long long             ll;
typedef unsigned long long    ull;
typedef long double           lld;
typedef vector<int>           vi;
typedef vector<vi>            vvi;
typedef vector<long long>     vll;
typedef pair<int,int>         pii;
typedef pair<ll,ll>           pll;
typedef vector<pii>           vpii;
typedef vector<pll>           vpll;
typedef vector<bool>          vb;
typedef vector<vb>            vvb;

ll mod_add(ll a, ll b, ll m) {return (a%m + b%m)%m;}
ll mod_mul(ll a, ll b, ll m) {return (a%m * b%m)%m;}
ll mod_sub(ll a, ll b, ll m) {return (a%m - b%m)%m;}
/*/------------------------------ CODE BEGINS ------------------------------/*/

ll solve(){
    int n; cin>>n;
    vector<ll> vec(n,0);
    for(int i=0;i<n;i++)
        cin>>vec[i];
    
    ll currScore = 0;
    currScore += vec[0];
    for(int i=1;i<n;i++){
        if(vec[i]>vec[i-1]) 
        currScore += vec[i]-vec[i-1];
    }
    currScore += vec[n-1];
    for(int i=n-2;i>=0;--i){
        if(vec[i]>vec[i+1]) 
        currScore += vec[i]-vec[i+1];
    }

    ll toSubtract = 0;
    for(int i=1;i<n-1;i++){
        if(vec[i]>vec[i-1] && vec[i]>vec[i+1]){
            toSubtract += vec[i]-max(vec[i-1],vec[i+1]);
        }
    }

    if(n==1)
    toSubtract += vec[0];

    if(n>1){
        if(vec[0]>vec[1])
        toSubtract += vec[0]-vec[1];
        if(vec[n-1]>vec[n-2])
        toSubtract += vec[n-1]-vec[n-2];
    }

    return currScore-toSubtract;


}
/*/------------------------------- CODE ENDS -------------------------------/*/

int main(){
    fastio;
    // cout << setprecision(12) << fixed;
    int tc=1;
    cin>>tc;
    //precompute();
    for(int t=1;t<=tc;t++){
        // cout<<"Case #" << t  << ": ";
        cout<<solve()<<endl;
    }
    return 0;
}
