// 
// Nabajyoti Majumdar

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

using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int mod=1e9+7;
const int inf=INT_MAX;

void setIO(string name = "") { // name is nonempty for USACO file I/O

      ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output

      // if(sz(name)){

      //       freopen((name+".in").c_str(), "r", stdin); // see Input & Output

      //       freopen((name+".out").c_str(), "w", stdout);

      // }
      return;

}

int dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}};


void solve(){
   ll n;
   cin>>n;
   vector<ll>v(n+2);
   v[0]=0;
   ll sum=0;
   for(ll i=1;i<=n;i++){
      cin>>v[i];
      sum+=abs(v[i]-v[i-1]);
   }
   sum+=abs(v[n+1]-v[n]);

   ll sub=0;
   for(int i=1;i<=n;i++){
      // if it is a local maxima
      if(v[i]>v[i-1] && v[i]>v[i+1]){
         sub+=v[i]-max(v[i-1],v[i+1]);
      }
   }
   sum-=sub;
   cout<<sum<<endl;

   
}

int main(){
   setIO();
   
   //--------------//
   int t;
   cin>>t;
   while(t--){
      solve();
   }
   //------------//


   return 0;
}

