#include<iostream>
#include<cstdio>
using namespace std;
long long n,m,f[500001],ans;
int main(){
	scanf("%lld",&m);
	while(m){
		m--;
		scanf("%lld",&n);
		for(long long i=1ll;i<=n;i++)scanf("%lld",&f[i]);
		for(long long i=1ll;i<=n;i++){
			if(max(f[i+1ll],f[i-1ll])<f[i]){
				ans=ans+f[i]-max(f[i+1ll],f[i-1ll]);
				f[i]=max(f[i+1ll],f[i-1ll]);
			}
		}
		for(long long i=0ll;i<=n;i++){
			if(f[i]>f[i+1ll])ans=ans+f[i]-f[i+1ll];
			else ans=ans+f[i+1ll]-f[i];
		}
		printf("%lld\n",ans);
		for(long long i=1ll;i<=n;i++)f[i]=0ll;
		ans=0ll;
	}
}
