To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that the programs that work with fractions in this representations aren't complete, they lack supporting the operation of reducing fractions. Implement this operation and the Empire won't forget you.
The first input line contains two space-separated integers *n*, *m* (1 ≤ *n*, *m* ≤ 10<sup class="upper-index">5</sup>) that show how many numbers the first set (the numerator) and the second set (the denominator) contain, correspondingly.

The second line contains *n* space-separated integers: *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">7</sup>) — the numbers that are multiplied to produce the numerator.

The third line contains *m* space-separated integers: *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*m*</sub> (1 ≤ *b*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">7</sup>) — the numbers that are multiplied to produce the denominator.
 ######      ###      #######    #######    ##      #     #####        ###     ##### 
 #     #    #   #          #        #       # #     #    #     #      #   #     ###  
 #     #   #     #        #         #       #  #    #   #       #    #     #    ###  
 ######   #########      #          #       #   #   #   #           #########    #   
 ######   #########     #           #       #    #  #   #           #########    #   
 #     #  #       #    #            #       #     # #   #    ####   #       #    #   
 #     #  #       #   #             #       #      ##   #    #  #   #       #        
 ######   #       #  #######     #######    #       #    #####  #   #       #    #   

from __future__ import print_function # for PyPy2
import io
import os
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *

g   = lambda : stdin.readline().strip()
gl  = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")                      
# range = xrange

print(g())
a, b = gil(), gil()
A, B = 1, 1
po = {}
for v in a:
	A*=v

for v in b:
	B*=v

n = int(1e7)+1
p = [(i if i&1 else 2) for i in range(n+1)]
n_ = int(ceil(sqrt(n)))
for i in range(3, n, 2):
	if A==1 or B==1:break
	if p[i]:
		if i<= n_:
			for j in range(i+i, n+1, i):
				p[j] = min(i, p[j])
		while A%i == 0 and B%i == 0:
			po[i] = po.get(i, 0)+1
			A//=i
			B//=i

while not(A&1 or B&1):
	A//=2
	B//=2        
	po[2] = po.get(2, 0) + 1

bo = po.copy()

for i in range(len(a)):
	v = a[i]
	while v > 1:
		if po.get(p[v], 0):
			po[p[v]] -= 1 
			a[i] //= p[v]
		v //= p[v]
	a[i] = str(a[i])
    
for i in range(len(b)):
	v = b[i]
	while v > 1:
		if bo.get(p[v], 0):
			bo[p[v]] -= 1
			b[i] //= p[v]
		v //= p[v]
	b[i] = str(b[i]) 

print("".join(a))
print("".join(b))



		