// Arup Guha
// 10/29/2015
// Solution to 2000 UCF HS Contest Problem: Ultimate Fantasy Tactics

import java.util.*;

public class tactics {

	public static int[] mine;
	public static int[] opp;
	public static int[] bestPerm;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int loop = 1;

		// Process all cases.
		while (n != 0) {

			// Read in data.
			mine = new int[n];
			for (int i=0; i<n; i++)
				mine[i] = stdin.nextInt();
			int m = stdin.nextInt();
			opp = new int[m];
			for (int i=0; i<m; i++)
				opp[i] = stdin.nextInt();

			// Store best and current permutations, respectively.
			bestPerm = null;
			int[] perm = new int[n];

			// Solve it and output result.
			go (perm, 0);
			output(loop);

			// Get next case.
			n = stdin.nextInt();
			loop++;
		}
	}

	// Almost as annoying as the farm problem from 2004...
	public static void output(int loop) {

		System.out.println("+==========================================+");
		System.out.printf("| Battle #%-5d                            |\n", loop);
		System.out.println("+==========================================+");
		System.out.println("| Party Member        Enemy                |");
		System.out.println("| ------------        -----                |");
		for (int i=0; i<bestPerm.length; i++)
			System.out.println("| "+(i+1)+"                   "+(bestPerm[i]+1)+"                    |");;
		System.out.println("+==========================================+");

		// Recalculate so we can print this.
		int[] oppPts = sim(bestPerm);
		System.out.printf("| WDF: %-10.3f     LDF: %-10.3f      |\n", WDF(oppPts), LDF(oppPts));
		System.out.println("+==========================================+");
		System.out.println();
	}

	// Typical recursive "odometer" function tries all possibilities of each person
	// attacking each defender.
	public static void go(int[] perm, int k) {

		// Filled in a permutation, evaluate it.
		if (k == perm.length) {
			if (bestPerm == null || beat(perm, bestPerm))
				bestPerm = Arrays.copyOf(perm, perm.length);
			return;
		}

		// Try each possible item in slot k.
		for (int i=0; i<opp.length; i++) {
			perm[k] = i;
			go(perm, k+1);
		}
	}

	// Returns true iff perm1 is better than perm2, for attacking.
	public static boolean beat(int[] perm1, int[] perm2) {

		// Simulate attacks.
		int[] oppPts1 = sim(perm1);
		int[] oppPts2 = sim(perm2);

		// First see if there are a different number of kills.
		int k1 = kills(oppPts1);
		int k2 = kills(oppPts2);
		if (k1 > k2) return true;
		if (k1 < k2) return false;

		// Now break ties based on minimum WDF.
		double wdf1 = WDF(oppPts1);
		double wdf2 = WDF(oppPts2);
		if (wdf1 < wdf2-1e-6) return true;
		if (wdf1 > wdf2+1e-6) return false;

		// Then minimum LDF.
		return LDF(oppPts1) < LDF(oppPts2);
	}

	// Simulates this permutation and returns the opponents resulting HP.
	public static int[] sim(int[] perm) {

		// Simulate attacks.
		int[] oppPts = Arrays.copyOf(opp, opp.length);
		for (int i=0; i<perm.length; i++)
			oppPts[perm[i]] -= mine[i];

		return oppPts;
	}

	// Returns the number of kills based on the opponent's status oppPts.
	public static int kills(int[] oppPts) {

		// Count up how many opponents are killed.
		int killCnt = 0;
		for (int i=0; i<oppPts.length; i++)
			if (oppPts[i] <= 0)
				killCnt++;

		// Return it.
		return killCnt;
	}

	// Returns the WDF based on the opponent's status oppPts.
	public static double WDF(int[] oppPts) {

		// Count up wasted damage factor.
		double res = 0;
		for (int i=0; i<oppPts.length; i++)
			if (oppPts[i] < 0)
				res += (double)(-oppPts[i])/opp[i];

		// Return it.
		return res;
	}

	// Returns the LDF based on the opponent's status oppPts.
	public static double LDF(int[] oppPts) {

		// Count up wasted damage factor.
		double res = 0;
		for (int i=0; i<oppPts.length; i++)
			if (oppPts[i] > 0)
				res += (double)(oppPts[i])/opp[i];

		// Return it.
		return res;
	}
}