// Arup Guha
// 1/17/2014
// Solution to 2009 UCF Locals Problem: A Constant Struggle.

import java.util.*;

public class constant {
	
	final public static int NUMVARS = 8;
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.		
		for (int loop=1; loop<=numCases; loop++) {
			
			// Read data.
			int[] den = new int[NUMVARS];
			for (int i=0; i<NUMVARS; i++)
				den[i] = stdin.nextInt();
			Arrays.sort(den);
			
			int N = stdin.nextInt();
			
			// Set up first row of DP array.
			long[][] dp = new long[NUMVARS][N+1];
			for (int i=0; i<=N; i+=den[0])
				dp[0][i] = 1;
				
			// Exactly the numways to make change DP...
			for (int i=1; i<NUMVARS; i++) {
				for (int j=0; j<=N; j++) {
					dp[i][j] = dp[i-1][j];
					if (j >= den[i]) dp[i][j] += dp[i][j-den[i]];
				}
			}
			
			// Print result.
			System.out.println("Equation #"+loop+": "+dp[NUMVARS-1][N]);
		}
	}
}