// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#define dibs reserve
#define OVER9000 1234567890
#define tisic 47
#define soclose 10e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define uint unsigned int
// mylittlepony
using namespace std;
int main() {
int T;
cin >> T;
for(int i =0; i < T; i++) {
int N,P;
cin >> N >> P;
vector<int> p;
for(int j =2; j*j <= P; j++) if(P%j == 0) {
while(P%j == 0) P /=j;
p.push_back(j);}
if(P > 1) p.push_back(P);
int A =1;
for(int i =0; i < p.size(); i++) A *=2;
vector<int> seq(N+1,0);
for(int i =0; i < N; i++) cin >> seq[i+1];
vector< vector<int> > B(N+1, vector<int>(A,N+1));
B[0][0] =0;
// min. number of cuts for this subset of primes
for(int i =0; i < N; i++) for(int j =0; j < A; j++) if(B[i][j] <= N) {
int s =0;
for(int k =i+1; k <= N; k++) {
s +=seq[k];
int x =j;
for(int l =0; l < p.size(); l++)
if(s%p[l] == 0) x |=(1<<l);
B[k][x] =min(B[k][x],B[i][j]+1);}
}
int ans =0, ansC =N;
for(int i =0; i < A; i++) if(B[N][i] <= N) {
int x =1;
for(int j =0; j < p.size(); j++) if((i&(1<<j)) != 0) x *=p[j];
if(ans < x) {ans =x; ansC =N;}
if(ansC > B[N][i]) ansC =B[N][i];}
cout << ans << " " << ansC-1 << "\n";}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbH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