import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		long res = 0;
		foreach (i; 0..n)
		{
			auto lo = 0;
			if (i > 0)
			{
				lo = max (lo, a[i - 1]);
			}
			if (i + 1 < n)
			{
				lo = max (lo, a[i + 1]);
			}
			int delta = max (0, a[i] - lo);
			a[i] -= delta;
			res += delta;
		}
		debug {writeln (a, " ", res);}
		res += a[0];
		res += a[n - 1];
		foreach (i; 1..n)
		{
			res += abs (a[i] - a[i - 1]);
		}
		writeln (res);
	}
}
