#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db double
#define str string
#define vc vector
#define its(a) (a).begin(), (a).end()
#define itsr(a) (a).rbegin(), (a).rend()
#define tstr(a) to_string((a))
#define INF ((ll)1e18)

void solve() {
    ll n, m; cin >> n >> m;
    vc<ll> b(m); 
    for (auto& i : b) cin >> i;

    if (n == 1) {
        cout << m % 2 * b[0] << '\n';
    }
    else {
        if (n <= m)
            cout << b[0] * n << "\n";
        else cout << b[0] * n - (n % m % 2) * b[0] << '\n';
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll _t = 1;
    cin >> _t;
    while (_t--)
        solve();
}
