import java.io.BufferedReader;
import java.io.FileReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

/**
 * Created with IntelliJ IDEA.
 * User: student
 * Date: 10.11.13
 * Time: 12:16
 * To change this template use File | Settings | File Templates.
 */
public class JavaK {

    public static int nod (int a, int b) {
        return a == 0 ? b : nod(b%a,a);
    }

    public static void main(String[] args) throws Throwable {
        BufferedReader reader = new BufferedReader(new FileReader("NUMBERS.IN"));
        int tests = Integer.valueOf(reader.readLine()).intValue();

        for (int ii = 0; ii < tests; ++ii) {
            StringTokenizer st = new StringTokenizer(reader.readLine());
            int n = Integer.valueOf(st.nextToken()).intValue();
            int m = Integer.valueOf(st.nextToken()).intValue();

            st = new StringTokenizer(reader.readLine());
            BigInteger nk = new BigInteger(st.nextToken());
            int nd = nk.intValue();
            for (int i = 1; i < n; ++i) {
                BigInteger t = new BigInteger(st.nextToken());
                nd = nod( nd, t.intValue() );
                nk = nk.multiply( t ).divide( nk.gcd( t ) );
            }

            System.out.print(nd);
            System.out.print(" ");
            System.out.print(nk.mod(BigInteger.valueOf(m)));
            System.out.println();
        }
    }
}
