def solve(): n = int(input()) a = list(map(int, input().split())) inf = int(1e18) dp = [-inf] * 6 dp[0] = dp[1] = 0 for i in range(n): ndp = [-inf] * 6 for j in range(3): if j < 2: ndp[2 * j + 2] = max(dp[2 * j], dp[2 * j + 1]) + a[i] ndp[2 * j + 3] = max(dp[2 * j], dp[2 * j + 1]) - a[i] ndp[2 * j] = max(ndp[2 * j], dp[2 * j] + a[i]) ndp[2 * j + 1] = max(ndp[2 * j + 1], dp[2 * j + 1] - a[i]) dp, ndp = ndp, dp print(max(dp[4], dp[5])) t = int(input()) for i in range(t): solve()