#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;
#define fi first
#define se second
#define mp make_pair

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        vector <ll> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        if (n == 1) {
            cout << a[0] << '\n';
        } else {
            ll ans = 0;
            if (a[0] > a[1]) {
                ans += (a[0] - a[1]);
                a[0] = a[1];
            }
            for (int i = 1; i < n - 1; i++) {
                if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
                    ans += a[i] - max(a[i - 1], a[i + 1]);
                    a[i] = max(a[i - 1], a[i + 1]);
                }
            }
            if (a[n - 1] > a[n - 2]) {
                ans += (a[n - 1] - a[n - 2]);
                a[n - 1] = a[n - 2];
            }
            ans += a[0] + a[n - 1];
            for (int i = 1; i < n; i++) {
                ans += abs(a[i] - a[i - 1]);
            }
            cout << ans << '\n';
        }
    }
    return 0;
}