// Arup Guha
// 3/17/2019
// Solution to 2019 MAPS Problem A: Bike Gears

import java.util.*;

public class bikegears {

	public static void main(String[] args) {
		
		// Read basic input.
		Scanner stdin = new Scanner(System.in);
		int numN = stdin.nextInt();
		int numD = stdin.nextInt();
		long[] nList = new long[numN];
		long[] dList = new long[numD];
		
		// Read numerators, denominators.
		for (int i=0; i<numN; i++) nList[i] = stdin.nextLong();
		for (int i=0; i<numD; i++) dList[i] = stdin.nextLong();
		
		// Form all fractions and sort.
		fraction[] fList = new fraction[numN*numD];
		for (int i=0; i<numN; i++)
			for (int j=0; j<numD; j++)
				fList[i*numD+j] = new fraction(nList[i], dList[j]);
		Arrays.sort(fList);
		
		// Ta da!
		for (int i=0; i<fList.length; i++)
			System.out.println(fList[i]);
	}	
}

class fraction implements Comparable<fraction> {
	
	public long n;
	public long d;
	
	public fraction(long myn, long myd) {
		n = myn;
		d = myd;
	}

	// This is how they told us to sort...
	public int compareTo(fraction other) {
		if (n*other.d < d*other.n) return -1;
		if (n*other.d > d*other.n) return 1;
		if (n < other.n) return -1;
		if (n > other.n) return 1;
		return 0;
	}
	
	public String toString() {
		return "("+n+","+d+")";
	}
}