#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
typedef struct {
int a;
int idx;
} Pair;
Pair *pairs;
int n, x;
int compare(const void *a, const void *b) {
Pair *pa = (Pair *)a;
Pair *pb = (Pair *)b;
return pa->a - pb->a;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &x);
pairs = (Pair *)malloc(n * sizeof(Pair));
for (int i = 0; i < n; i++) {
scanf("%d", &pairs[i].a);
pairs[i].idx = i + 1;
}
qsort(pairs, n, sizeof(Pair), compare);
int min_loss = INT_MAX;
int optimal_k = 0;
for (int k = 1; k <= x; k++) {
int loss = 0;
int prev_idx = -1;
for (int i = 0; i < n; i++) {
if (pairs[i].a % k == 0 && (prev_idx == -1 || pairs[i].idx != pairs[prev_idx].idx + 1)) {
loss += pairs[i].a;
prev_idx = i;
}
}
if (loss < min_loss) {
min_loss = loss;
optimal_k = k;
}
}
printf("%d\n", optimal_k);
free(pairs);
}
return 0;
}