#include <iostream>
#include <vector>

#define int long long
constexpr int INF = 4e18;

void solve()
{
    int n, m;
    std::cin >> n >> m;
    std::vector<int> x(m + 1);
    for (int i = 1; i <= m; ++i)
        std::cin >> x[i];
    std::vector<int> dp1(m + 2, -INF), dp2(m + 2, -INF), dp3(m + 2, INF), dp4(m + 2, INF);
    dp1[0] = 0;
    dp2[0] = 0;
    dp3[0] = 0;
    dp4[0] = 0;
    dp1[1] = 0;
    dp2[1] = 0;
    dp3[1] = 0;
    dp4[1] = 0;
    for (int i = 2; i <= m + 1; ++i) {
        int x2 = 0;
        for (int j = i - 1; j >= 1; --j) {
            int x1 = x[i - 1] - x[j - 1];
            if ((i - j) % 2 == 1) {
                dp1[i] = std::max(dp1[j - 1] + x1 + x2, dp1[i]);
                dp4[i] = std::min(dp4[j - 1] + x1 + x2, dp4[i]);
                dp2[i] = std::max(dp2[j - 1] + x1 - x2, dp2[i]);
                dp2[i] = std::max(dp2[j - 1] - x1 + x2, dp2[i]);
                dp3[i] = std::min(dp3[j - 1] + x1 - x2, dp3[i]);
                dp3[i] = std::min(dp3[j - 1] - x1 + x2, dp3[i]);
            } else {
                dp1[i] = std::max(x1 + x2 + dp2[j - 1], dp1[i]);
                dp1[i] = std::max(x1 + x2 - dp3[j - 1], dp1[i]);
                dp4[i] = std::min(x1 + x2 + dp3[j - 1], dp4[i]);
                dp4[i] = std::min(x1 + x2 - dp2[j - 1], dp4[i]);
                dp2[i] = std::max(x1 - x2 + dp1[j - 1], dp2[i]);
                dp2[i] = std::max(x2 - x1 - dp4[j - 1], dp2[i]);
                dp3[i] = std::min(x1 - x2 + dp4[j - 1], dp3[i]);
                dp3[i] = std::min(x2 - x1 - dp1[j - 1], dp3[i]);
            }
            if ((i - j) % 2 == 1)
                x2 += x[j - 1];
            else
                x2 -= x[j - 1];
        }
    }
    std::cout << dp1[m + 1] << '\n';
}

signed main()
{
    int t = 1;
#ifdef LOCAL
    freopen("stream/inb.txt", "r", stdin);
    freopen("stream/outb.txt", "w", stdout);
    std::cin >> t;
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> t;
#endif
    for (int i_t = 1; i_t <= t; ++i_t) {
#ifdef LOCAL
    std::cout << "Test case " << i_t << '\n';
#endif
        solve();
    }
    std::cout.flush();
    return 0;
}