// Arup Guha
// 4/12/2023
// Solution to 2017 MAPS Problem I: Train Addiction

import java.util.*;

public class trainaddiction {

	final public static int DPSIZE = 51*51*51;
	final public static long MOD = 1000000007L;
	
	public static long[] freq;
	public static int div;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=0; loop<nC; loop++) {
		
			// Store numbers in a frequency array and get their gcd.
			int n = stdin.nextInt();
			int nT = stdin.nextInt();
			freq = new long[50];
			div = -1;
			for (int i=0; i<nT; i++) {
				int tmp = stdin.nextInt();
				freq[tmp-1]++;
				if (div == -1) div = tmp;
				else div = gcd(div, tmp);
			}
			
			// We'll turn this to false if it's impossible.
			boolean flag = true;
			
			// Easy divisibility check.
			if (n%div != 0) flag = false;
			
			// All other impossible cases will be limited by the cube of the smallest #, I think,
			// or maybe less, but I am being safe, so I can just run a DP for this potential case.
			else if (n < DPSIZE) {
				boolean[] dp = getBoolDPArray(n);
				if (!dp[n]) flag = false;
			}
			
			if (!flag)
				System.out.println("IMPOSSIBLE");
			
			// Matrix expo solution will work.
			else {
			
				// Stores first 50 values.
				long[][] col = getDPArray(50);
				
				// Answer is in column just print it.
				if (n<=50)
					System.out.println(col[50-n][0]);
				
				// Here we have to exponentiate with our matrix.
				else {
					
					// Matrix to multiply by.
					long[][] m = new long[50][50];
					for (int i=0; i<50; i++) m[0][i] = freq[i];
					for (int i=1; i<50; i++) m[i][i-1] = 1;
					
					// power to raise matrix to.
					int exp = n-50;
					
					// This is our matrix raised to the appropriate power.
					// Basically, multiplying by m once calculates f(n+1) given
					// the previous 50 values f(n), f(n-1),..., f(n-49) by applying
					// the appropriate recurrence relation of adding each possible train
					// as the last train in the chain which builds off smaller chains.
					long[][] mexp = matExpo(m, exp);
					
					// When we multiply this matrix with the column f(50), f(49),...,f(1)
					// our final answer will be at the top.
					long[][] resCol = mult(mexp, col);
					System.out.println(resCol[0][0]);
				}
			}
		}
	}
	
	// returns m to the power exp, via fast matrix expo, modding each value by MOD.
	public static long[][] matExpo(long[][] m, int exp) {
		
		if (exp == 0) return identity(m.length);
		
		if (exp%2 == 0) {
			long[][] tmp = matExpo(m, exp/2);
			return mult(tmp, tmp);
		}
		
		long[][] tmp = matExpo(m, exp-1);
		return mult(tmp, m);
	}
	
	// Returns the identity matrix.
	public static long[][] identity(int n) {
		long[][] res = new long[n][n];
		for (int i=0; i<n; i++) res[i][i] = 1;
		return res;
	}
	
	// Returns a x b.
	public static long[][] mult(long[][] a, long[][] b) {
		
		long[][] c = new long[a.length][b[0].length];
		
		for (int i=0; i<a.length; i++) 
			for (int j=0; j<b[0].length; j++) 
				for (int k=0; k<a[0].length; k++)
					c[i][j] = (c[i][j] + a[i][k]*b[k][j])%MOD;
		return c;
	}
	
	// Runs the DP so that answer[i] = true iff we can make a train of size n.
	public static boolean[] getBoolDPArray(int n) {
		
		boolean[] res = new boolean[n+1];
		res[0] = true;
		
		// Run regular DP forward since we can use as many copies of each train.
		for (int i=0; i<50; i++) {
			if (freq[i] == 0) continue;
			for (int j=i+1; j<=n; j++)
				if (res[j-i-1])
					res[j] = true;
		}
		
		return res;
	}
	
	// Returns column vector for multiplication.
	public static long[][] getDPArray(int n) {
		
		// dp[i] will store # of trains
		long[] dp = new long[n+1];
		dp[0] = 1;
		for (int i=1; i<=n; i++) {
			for (int j=0; j<50; j++) {
				if (i-j-1 < 0) break;
				dp[i] = (dp[i] + dp[i-j-1]*freq[j])%MOD;
			}
		}
		
		// Column will store f(n) on top, f(1) on bottom.
		long[][] res = new long[n][1];
		
		for (int i=n-1; i>=0; i--) 
			res[i][0] = dp[n-i];
		return res;
	}
	
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a%b);
	}
}