// #pragma GCC optimize("Ofast,fast-math,unroll-loops,no-stack-protector,inline")
#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    freopen("input.txt", "r", stdin);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        int n, m;
        cin >> n >> m;
        vector<int> arr(m);
        for (int i = 0; i < m; i++) {
            cin >> arr[i];
        }
        if (n > m) {
            cout << m * arr[0] << endl;
        } else {
            int cur = m - n;
            bool fl = 1;
            for (int i = 2; i <= n; i++) {
                if (cur % i == 0) {
                    fl = 0;
                    break;
                }
            }
            cout << (m - fl) * arr[0] << endl;
        }
    }
}