#include <iostream>
#include <algorithm>
using namespace std;
FILE* stream;
int N;
#define MAX_N 1000
int input[MAX_N];
int fnSolve() {
int Ret = 0;
for (int i = 2; i < N - 2; i++) {
int Max = 0;
int Min = 987654321;
for (int j = i - 2; j <= i + 2; j++) {
Max = max(Max, input[j]);
}
if (input[i] == Max) {
Min = min(Min, input[i] - input[i - 2]);
Min = min(Min, input[i] - input[i - 1]);
Min = min(Min, input[i] - input[i + 2]);
Min = min(Min, input[i] - input[i + 1]);
Ret += Min;
}
}
return Ret;
}
int main(void) {
freopen_s(&stream, "input.txt", "r", stdin);
for (int t = 1; t <= 10; t++) {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> input[i];
}
cout << "#" << t << " " << fnSolve() << endl;
}
}