#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int p[n]={0};
int tt=0;
int maxim=0;
for(int i=1;i<n;i++){
cin>>p[i];
if((p[i]>p[i-1]) && (p[i]>=maxim)){
tt=tt+2*p[i]-maxim;
maxim=max(p[i],maxim);
}else{
tt=tt+p[i];
}
}
cout<<tt<<endl;
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: