#include <bits/stdc++.h>
#include <bits/extc++.h>

#ifndef LOCAL
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unrool-looops")
#endif

std::random_device rd;
std::mt19937_64 gen(rd());

using namespace __gnu_pbds;
using ll = long long;

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

void not_main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> x(m);
    for (int i = 0; i < m; ++i) {
        std::cin >> x[i];
    }
    if (n >= m) {
        std::cout << 1ll * x[0] * m << '\n';
        return;
    }
    std::cout << 1ll * x[0] * (n - 1) + x[0] * ((m - n) % 2 == 0) << '\n';
}

signed main() {
    std::ios_base::sync_with_stdio(false);
#ifndef LOCAL
    std::cin.tie(nullptr);
#endif
    int tests = 1;
    std::cin >> tests;
    while (tests--) {
        not_main();
    }
    return 0;
}