#include<bits/stdc++.h>
using namespace std;

#define fastio() ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define ll long long int
#define loop(i,k,n) for(i=k; i<n; i++)
#define rloop(i,n,k) for(i = n-1; i >= k; i--)
#define trv(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define between(v,x,y) v.begin()+x,v.begin()+y
#define armin(v) *min_element(all(v))
#define armax(v) *max_element(all(v))
#define posmin(v) min_element(all(v)) - v.begin()
#define posmax(v) max_element(all(v)) - v.begin()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define clr(x) memset(x,0,sizeof(x))
#define oparr(v) for(auto x:v) cout << x << " " ; cout << '\n'
#define f first
#define s second

template<class T> void inp(T& x) {
	cin >> x;
}
template<class H, class... T> void inp(H& h, T&... t) {
	inp(h);
	inp(t...);
}
template<class A> void inp(vector<A>& x) {
	trv(a, x)
		inp(a);
}
void deb_out() { cerr << endl; }
template<typename Head, typename... Tail> void deb_out(Head H, Tail... T) { cerr << ' ' << H; deb_out(T...); }
#define deb(...) cerr << "(" << #__VA_ARGS__ << "):", deb_out(__VA_ARGS__)

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ll> vll;

const ll mod = 1e9 + 7;
const char nl = '\n';

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/__gcd(a,b) 
#define msb(n) __builtin_clz(n)

int i,j;

void solve(){
	int n; inp(n);
	vll a(n); inp(a);
	if(n == 1){
		cout << a[0] << nl;
		return;
	}
	ll cost = 0;
	loop(i,1,n-1){
		if(a[i] > a[i-1] and a[i] > a[i+1]){
			cost += abs(a[i] - max(a[i-1],a[i+1]));
			a[i] = max(a[i-1],a[i+1]);
		}
	}
	// ends :
	if(n > 1 and a[0] > a[1]){
		cost += a[0] - a[1];
		a[0] = a[1];
	}
	if(n > 1 and a[n-1] > a[n-2]){
		cost += a[n-1] - a[n-2];
		a[n-1] = a[n-2];
	}
	ll ans = a[0] + a[n-1];
	loop(i,1,n) ans += abs(a[i] - a[i-1]);
	cout << cost + ans << nl;
}

int main(){

	fastio();
	int t = 1;
    inp(t);
	int x = t;
    while(t--){
		//cout << "Case #" << x-t << ": ";
		solve();
	}
 return 0;
}
