#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define int long long

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, m;
    vector<int> b;
    multiset<int> a;
    cin >> n >> m;
    b.resize(m);
    for (auto &x: b) cin >> x;
    for (int i = 0; i < n; i++)
        a.emplace(0);
    int res = 0;
    if ((m / n) % 2) {
        res = b[0] * n;
        for (int i = 0; i < m % n; i++)
            res -= b[0];
    } else {
        for (int i = 0; i < m % n; i++)
            res += b[0];
    }
    cout << res << '\n';
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
