#include <iostream>
#include <vector>
#include <algorithm>
#define dd(x) cout << #x << "=" << x << ", "
#define de(x) cout << #x << "=" << x << endl
using namespace std;
typedef long long i64;
/* If u think it all right but WA, check the problem limits. */

// template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {return out << "(" << p.x << ", " << p.y << ")";}
// template<class A> ostream& operator <<(ostream& out, const vector<A> &v) {out << "["; for(int i=0;i<v.size();++i) { if(i) out << ", "; out << v[i];	}	return out << "]";}

void sol() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }

  if(n==1) {
    cout << a[0] << endl;
    return;
  }

  i64 delta=0;
  if(a[0]>a[1]) {
    delta += a[0]-a[1];
    a[0] = a[1];
  }
  if(a[n-1]>a[n-2]) {
    delta += a[n-1]-a[n-2];
    a[n-1] = a[n-2];
  }
  for(int i=1;i<n-1;++i) {
    int mx = max(a[i-1],a[i+1]);
    if(a[i]>mx) {
      delta += a[i]-mx;
      a[i] = mx;
    }
  }

  i64 ugl = a[0] + a.back();
  for(int i=1;i<n;++i) {
    ugl += abs(a[i]-a[i-1]);
  }
  i64 ans = delta + ugl;
  cout << ans << endl;
}

int main(int argc, char const *argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);

  // freopen("in.txt","r",stdin);

  int t;
  cin >> t;
  for(;t;--t) {
    sol();
  }

  return 0;
}
