#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2007, inf = 1e18;

int dp[N][N];

signed main() {
    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];
        }
        int zn = min(n, m);
        cout << zn*x[0] << endl;
    }
}
