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

using namespace std;
using namespace __gnu_pbds;

#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    int x;
    for (int i = 0; i < m; i++) {
        cin >> x;
    }m = m % (2 * n);
    if (m < n) {
        cout << m * x << "\n";
    } else {
        cout << n * x - (m - n) * x << "\n";
    }
}

signed main() {
    int t;
    cin >> t;
    while (t--) solve();
}
