#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MP make_pair
#define all(v) (v).begin(), (v).end()
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
ll CountLeq(ll x, int power) {
if (power == 1) {
return x - 1;
}
double t = pow(double(x), 1.0 / power);
for (int ans = ceil(t) + 2; ; --ans) {
ll powans = 1;
bool good = true;
for (int i = 1; i <= power; ++i) {
if (x / ans >= powans) {
powans *= ans;
} else {
good = false;
break;
}
}
if (good && powans <= x) {
return ans - 1;
}
}
}
ll CountLeq(ll x, const vi& coeffs) {
if (x == 1) {
return 1;
}
ll result = 1;
for (int i = 1; i < coeffs.size(); ++i) {
if (coeffs[i]) {
result += CountLeq(x, i) * coeffs[i];
}
}
return result;
}
int main() {
int tests;
cin >> tests;
for (int test_index = 0; test_index < tests; ++test_index) {
int N, m;
scanf("%d%d", &N, &m);
vi pows(m);
for (int i = 0; i < m; ++i) {
scanf("%d", &pows[i]);
}
sort(pows.begin(), pows.end());
vb is_needed(61, false);
for (int i = 0; i < pows.size(); ++i) {
for (int j = 1; j * pows[i] < 61; ++j) {
is_needed[j * pows[i]] = true;
}
}
vi coeffs(61, 0);
for (int i = 1; i < 61; ++i) {
if (!is_needed[i]) {
continue;
}
int sum = 0;
for (int j = 1; j < i; ++j) {
if (i % j == 0) {
sum += coeffs[j];
}
}
coeffs[i] = 1 - sum;
}
ll low = 1;
ll high =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IHRlc3RzOwogIGZvciAoaW50IHRlc3RfaW5kZXggPSAwOyB0ZXN0X2luZGV4IDwgdGVzdHM7ICsrdGVzdF9pbmRleCkgewogICAgaW50IE4sIG07CiAgICBzY2FuZigiJWQlZCIsICZOLCAmbSk7CiAgICB2aSBwb3dzKG0pOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyArK2kpIHsKICAgICAgc2NhbmYoIiVkIiwgJnBvd3NbaV0pOwogICAgfQogICAgc29ydChwb3dzLmJlZ2luKCksIHBvd3MuZW5kKCkpOwogICAgdmIgaXNfbmVlZGVkKDYxLCBmYWxzZSk7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IHBvd3Muc2l6ZSgpOyArK2kpIHsKICAgICAgZm9yIChpbnQgaiA9IDE7IGogKiBwb3dzW2ldIDwgNjE7ICsraikgewogICAgICAgIGlzX25lZWRlZFtqICogcG93c1tpXV0gPSB0cnVlOwogICAgICB9CiAgICB9CiAgICB2aSBjb2VmZnMoNjEsIDApOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCA2MTsgKytpKSB7CiAgICAgIGlmICghaXNfbmVlZGVkW2ldKSB7CiAgICAgICAgY29udGludWU7CiAgICAgIH0KICAgICAgaW50IHN1bSA9IDA7CiAgICAgIGZvciAoaW50IGogPSAxOyBqIDwgaTsgKytqKSB7CiAgICAgICAgaWYgKGkgJSBqID09IDApIHsKICAgICAgICAgIHN1bSArPSBjb2VmZnNbal07CiAgICAgICAgfQogICAgICB9CiAgICAgIGNvZWZmc1tpXSA9IDEgLSBzdW07CiAgICB9CiAgICBsbCBsb3cgPSAxOwogICAgbGwgaGlnaCA9IGxsKDEwMDAwMDAwMDApICogbGwoMTAwMDAwMDAwKTsKICAgIHdoaWxlIChsb3cgPCBoaWdoKSB7CiAgICAgIGxsIG1pZCA9IChsb3cgKyBoaWdoKSAvIDI7CiAgICAgIGxsIGxlc3NfeCA9IENvdW50TGVxKG1pZCwgY29lZmZzKTsKICAgICAgaWYgKGxlc3NfeCA8IE4pIHsKICAgICAgICBsb3cgPSBtaWQgKyAxOwogICAgICB9IGVsc2UgewogICAgICAgIGhpZ2ggPSBtaWQ7CiAgICAgIH0KICAgIH0gICAKICAgIGNvdXQgPDwgbG93IDw8IGVuZGw7CiAgfQogIHJldHVybiAwOwp9Cg==