// Arup Guha
// 5/28/2016
// Solution to 2014 NCNA Problem H: Continued Fractions

import java.util.*;

public class fractions {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int caseNum = 1;

		// Process each case.
		while (stdin.hasNext()) {

			// Get this case.
			int n = stdin.nextInt();
			int m = stdin.nextInt();
			int[] op1 = new int[n];
			for (int i=0; i<n; i++) op1[i] = stdin.nextInt();
			int[] op2 = new int[m];
			for (int i=0; i<m; i++) op2[i] = stdin.nextInt();

			// Form fraction objects.
			fraction f1 = new fraction(op1);
			fraction f2 = new fraction(op2);

			// Do each operation.
			fraction sum = f1.add(f2);
			fraction diff = f1.sub(f2);
			fraction prod = f1.mult(f2);
			fraction quo = f1.div(f2);

			// Output result.
			System.out.println("Case "+caseNum+":");
			sum.print();
			diff.print();
			prod.print();
			quo.print();			
			caseNum++;
		}
	}
}

class fraction {

	public long num;
	public long den;

	// Converts the list they give us into a fraction object.
	public fraction(int[] list) {
		fraction cur = new fraction(list[list.length-1], 1L);
		for (int i=list.length-2; i>=0; i--) {
			cur = cur.reciprocal();
			fraction tmp = new fraction(list[i], 1L);
			cur = cur.add(tmp);			
		}

		num = cur.num;
		den = cur.den;
	}

	public fraction(long n, long d) {
		long div = gcd(n, d);
		num = n/div;
		den = d/div;
	}

	public fraction reciprocal() {
		return new fraction(den, num);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a%b);
	}

	public fraction add(fraction other) {
		return new fraction(num*other.den+other.num*den, den*other.den);
	}

	// Does abs of subtraction as desired for the problem.
	public fraction sub(fraction other) {
		return new fraction(Math.abs(num*other.den-other.num*den), den*other.den);
	}

	public fraction mult(fraction other) {
		return new fraction(num*other.num, den*other.den);
	}

	public fraction div(fraction other) {
		return new fraction(num*other.den, den*other.num);
	}

	// Prints in the format desired for the problem.
	public void print() {
		long n = num;
		long d = den;
		boolean space = false;
		while (d > 0) {
			if (space) System.out.print(" ");
			System.out.print(n/d);
			long newn = d;
			long newd = n%d;
			n = newn;
			d = newd;
			space = true;	
		}
		System.out.println();
	}
}