//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
using namespace std;
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second




#define si(x) int(x.size())
#define sum_all(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())



void solve()
{
 
  ll n ;
  cin >> n;
  vector<ll>arr(n+2);
  arr[0]=arr[n+1]=0;
  for(ll i=1;i<=n;i++)
  	cin >> arr[i];
ll ans=0;
for(ll i=1;i<n+2;i++)
{
	ans+=abs(arr[i]-arr[i-1]);
}
// cout << ans << endl;
for(ll i=1;i<=n;i++)
{
	ll x=max(arr[i-1],arr[i+1]);
	if(arr[i]>x)
	{
		ans-=(arr[i]-x);
        arr[i]=x; 
	}
}

cout << ans << endl;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif



    int t; cin >> t; while (t--)
    solve();

}
