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

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using o_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;

//find_by_order()
//order_of_key()

void solve() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
    if ((m / n) % 2 == 0) {
        cout << a[0] * (m % n) << '\n';
    } else {
        cout << a[0] * (m - (m % n)) << '\n';
    }
}

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