#include<bits/stdc++.h>
#pragma GCC target("avx2")
//#define int long long
#define F first
#define S second

using namespace std;

const int N = 5e5+10;

bool us[N];

const int C = 1300;

bool dp[2][2*C+10][2*C+10];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n, m;
        cin>>n>>m;
        int p[m+10];
        for(int i = 1; i <= m; i++)
        {
            int x;
            cin>>x;
            p[i] = x;
        }
        if(n > m)
        {
            cout<<p[1]*m<<"\n";
            continue;
        }
        cout<<p[1]*n-p[1]*!bool((m-n)%2)<<"\n";
    }
}

