#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    int T;
    cin>>T;
    while (T>0)
    {
        int n;
        scanf("%d", &n);
        long long int arr[n+2], count = 0, temp;
        arr[0]=0, arr[n+1]=0;
        for (int i = 1; i <= n; i++)
        {
            scanf("%lld", &arr[i]);
        }
        for (int i = 1; i <= n; i++)
        {
            if (arr[i]>arr[i-1] && arr[i]>arr[i+1])
            {
                temp = max(arr[i-1],arr[i+1]);
                count+=(arr[i]-temp);
                arr[i] = temp;
            }
            else if (arr[i]==arr[i-1] && arr[i-1]>0)
            {
                if (arr[i]>arr[i-2] && arr[i]>arr[i+1])
                {
                    temp = max(arr[i-2],arr[i+1]);
                    count += (2*(arr[i]-temp));
                    arr[i]=temp;
                    arr[i-1] = temp;
                }
                
            }
            
        }
        for (int i = 1; i <= n+1; i++)
        {
            count+= abs(arr[i]-arr[i-1]);
        }
        cout<<count<<endl;
        T--;
    }
    return 0;
}