#include <iostream>
#include <vector>
using namespace std;
int solution(vector<int> &building, int N) {
int sum = 0;
for (int i = 2; i < N - 2; i++) {
int max1 = max(building[i - 2], building[i - 1]);
int max2 = max(building[i + 1], building[i + 2]);
int total = max(max1, max2);
sum += (building[i] > total) ? building[i] - total : 0;
}
return sum;
}
int main() {
for (int t = 1; t <= 10; t++) {
int N; cin >> N;
vector<int> building;
for (int i = 0; i < N; i++) {
int n; cin >> n;
building.push_back(n);
}
cout << "#" << t<<" "<< solution(building, N) << endl;
}
return 0;
}