#include #include #include #include #include #include #include #include #include #include #include #include #define rf freopen("in.in", "r", stdin) #define wf freopen("out.out", "w", stdout) #define rep(i, s, n) for(int i=int(s); i<=int(n); ++i) using namespace std; const int mx = 1e5 + 10, mod = 1e9+7; int t; int n, k, l; int a[30], present[20]; int ncr[40][40]; int gcd[40][40]; int dp[(1 << 20) + 1][20]; int pos[30]; int nums[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 111}; void preprocess() { rep(i, 0, 39) { ncr[i][0] = 1; } rep (i, 1, 39) { rep (j, 1, 39) { ncr[i][j] = (ncr[i-1][j-1] + ncr[i-1][j]) % mod; } } rep (i, 1, 39) { rep (j, 1, 39) { gcd[i][j] = __gcd(i, j); } } int idx = 0; pos[1] = -1; rep (i, 2, 25) { if(i == 13 or i == 17 or i == 19 or i == 23) { pos[i] = pos[i-1]; } else { pos[i] = idx++; } } } int main() { //rf;// wf; ios::sync_with_stdio(0); preprocess(); cin >> t; while(t--) { cin >> n >> k >> l; assert(1 <= n && n <= 25); assert(1 <= k && k <= 25); assert(1 <= l && l <= 25); memset(present, 0, sizeof present); memset(dp, 0, sizeof dp); rep (i, 1, n) { cin >> a[i]; assert(1 <= a[i] && a[i] <= l); if(a[i] != 1 and a[i] != 13 and a[i] != 17 and a[i] != 19 and a[i] != 23) { present[pos[a[i]]] = 1; } } int free; if(l >= 1) free = 1; if(l >= 13) free = 2; if(l >= 17) free = 3; if(l >= 19) free = 4; if(l >= 23) free = 5; int check = 0; int presTemp[20]; int ans = 0; rep (i, 1, n) { if(a[i] == 1 or a[i] == 13 or a[i] == 17 or a[i] == 19 or a[i] == 23) { continue; } rep (j, 1, n) { int num = pos[gcd[a[i]][a[j]]]; if(num != -1 && present[num] == 0) { dp[0][num] = 1; check = 1; } } } if(check == 0) { ans = ncr[k - 1 + free][free - 1]; } int lim = 1 << (pos[l]+1); rep (i, 1, lim - 1) { int bitCount = __builtin_popcount(i); if(bitCount > k) { continue; } memcpy(presTemp, present, sizeof present); int newBit = -1; rep (j, 0, pos[l]) { if((i & (1 << j)) != 0) { newBit = j; presTemp[j] = 1; } } memcpy(dp[i], dp[i^(1<