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

//#pragma GCC optimize("O3")
//#pragma GCC target("avx2,bmi")

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define endl "\n"
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

constexpr int INF = 2e13;
constexpr int MOD = 1e9 + 7;



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        int n ,m;
        cin >> n >> m;
        vector<int> x(m);
        for (int i = 0; i < m; i++) {
            cin >> x[i];
        }
        m %= (2 * n);
        cout << m * x.front() << endl;
    }
}
