                              /*code_the_reality*/
                      
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
typedef long long ll;

bool comp(pair<ll,ll> a, pair<ll,ll> b){
   if(a.first!=b.first){
    return a.first<b.first;
   }else{
    return a.second<b.second;
   }
}
bool is_vowel(char c){
  if (c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
    return true;
  else
    return false;
}    
 bool is_prime(ll n){
  if(n==1)
    return false;
  for(ll i=2;i*i<=n;i++){
    if(n%i==0)
      return false;
  }
  return true;
 }

 ll max(ll a, ll b){
 if(a>b)
 return a;
 else
 return b;
 }
ll min(ll a, ll b){
 if(a<b)
 return a;
 else
 return b;
 }
void solve(){
int n;
cin>>n;
ll c[n + 2];
c[0] = 0;
c[n + 1] = 0;
for(int i = 1;i<=n;i++){
  cin>>c[i];
}
ll  org = 0;
for(int i = 1;i<=n+1;i++){
  org +=  abs(c[i] - c[i - 1]);
}
for(int i = 1; i<= n; i++){
  if(c[i] > c[i - 1] && c[i] > c[i + 1]){
    org = org - (2*c[i] - c[i + 1] - c[i-1]) + abs(c[i + 1] - c[i-1]) + c[i] - max(c[i + 1],c[i-1]);
  }
}
cout<<org;
}
int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
    solve();
    cout<<"\n";
    }
    return 0;
  }    