#include <bits/stdc++.h>
#define mii map<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define int long long
#define ii pair<int,int>
#define loop(i,a,b) for(int i=(a);i<(b);i++)
#define rloop(i,a,b) for(int i=(a);i>(b);i--)
#define tr(it,c) for(decltype((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define ft first
#define sd second
#define mod 998244353ll
#define mod2 1000000007ll
#define mem(a,b) memset(a,b,sizeof(a))
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.1415926535
#define double long double
 
using namespace std;



/********************************************************************************************************************************/



void solve()
{
	int n;
	cin>>n;
	int a[n+2];
	a[0]=0;
	loop(i,1,n+1)
	cin>>a[i];
	a[n+1]=0;
	
	int cost=0;
	loop(i,1,n+1)
	{
		int x=max(a[i-1],a[i+1]);
		if(a[i]>x)
		{
			cost+=a[i]-x;
			a[i]=x;
		}
	}
	loop(i,1,n+2)
	cost+=abs(a[i]-a[i-1]);
	cout<<cost;
}


signed main()
{
	

	SYNC;
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	
	
	int t=1;	
	cin>>t;
	loop(i,1,t+1)
	{	
		//cout<<"Case #"<<i<<": ";
		solve();
		cout<<"\n";
	}
}


