After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.

You're given a number X represented in base b_{x} and a number Y represented in base b_{y}. Compare those two numbers.


-----Input-----

The first line of the input contains two space-separated integers n and b_{x} (1 ≤ n ≤ 10, 2 ≤ b_{x} ≤ 40), where n is the number of digits in the b_{x}-based representation of X. 

The second line contains n space-separated integers x_1, x_2, ..., x_{n} (0 ≤ x_{i} < b_{x}) — the digits of X. They are given in the order from the most significant digit to the least significant one.

The following two lines describe Y in the same way: the third line contains two space-separated integers m and b_{y} (1 ≤ m ≤ 10, 2 ≤ b_{y} ≤ 40, b_{x} ≠ b_{y}), where m is the number of digits in the b_{y}-based representation of Y, and the fourth line contains m space-separated integers y_1, y_2, ..., y_{m} (0 ≤ y_{i} < b_{y}) — the digits of Y.

There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system.


-----Output-----

Output a single character (quotes for clarity):   '<' if X < Y  '>' if X > Y  '=' if X = Y 


-----Examples-----
Input
6 2
1 0 1 1 1 1
2 10
4 7

Output
=

Input
3 3
1 0 2
2 5
2 4

Output
<

Input
7 16
15 15 4 0 0 7 10
7 9
4 8 0 3 1 5 0

Output
>



-----Note-----

In the first sample, X = 101111_2 = 47_10 = Y.

In the second sample, X = 102_3 = 21_5 and Y = 24_5 = 112_3, thus X < Y.

In the third sample, $X = FF 4007 A_{16}$ and Y = 4803150_9. We may notice that X starts with much larger digits and b_{x} is much larger than b_{y}, so X is clearly larger than Y.

Difficulty: interview

Starter code:

Solutions:
n, bx = list(map(int, input().split()))
x1 = list(map(int, input().split()))
x = 0
for i in range(n):
	x *= bx
	x += x1[i]

n, by = list(map(int, input().split()))
y1 = list(map(int, input().split()))
y = 0
for i in range(n):
	y *= by
	y += y1[i]

if x == y:
	print('=')
elif x < y:
	print('<')
else:
	print('>')


import math
from decimal import *
import sys
from fractions import Fraction


inp=input().split()
n=int(inp[0])
bx=int(inp[1])
X=list(map(int,input().split()))
    
inp=input().split()
m=int(inp[0])
by=int(inp[1])
Y=list(map(int,input().split()))

x=0
t=1
for i in range(0,n):
   x += X[n-i-1]*t
   t *= bx

y=0
t=1
for i in range(0,m):
   y += Y[m-i-1]*t
   t *= by

if x<y:
    print("<")
if x==y:
    print("=")
if x>y:
    print(">")


n, bx = map(int, input().split())
s1 = 0
p1 = 1
for i in list(map(int, input().split()))[::-1]:
    s1 += i * p1
    p1 *= bx
m, by = map(int, input().split())
s2 = 0
p2 = 1
for i in list(map(int, input().split()))[::-1]:
    s2 += i * p2
    p2 *= by
if s1 == s2:
    print('=')
elif s1 > s2:
    print('>')
else:
    print('<')

a,b=map(int,input().split())
c=list(map(int,input().split()))
d,e=map(int,input().split())
f=list(map(int,input().split()))
n1=0
n2=0
for i in range(len(c)):
    n1+=c[i]*b**(len(c)-i-1)
for i in range(len(f)):
    n2+=f[i]*e**(len(f)-i-1)
if n1>n2:
    print('>')
elif n1==n2:
    print('=')
else:
    print('<')

n, bx = map(int, input().split())
X = list(map(int, input().split()))
m, by = map(int, input().split())
Y = list(map(int, input().split()))
resX, resY = 0, 0
for i in range(n):
    resX += X[-i - 1] * bx ** i
for i in range(m):
    resY += Y[-i - 1] * by ** i
if(resX < resY):
    print("<")
elif(resX == resY):
    print("=")
else:
    print(">")

a = []
for i in range(2):
    n, b = list(map(int, input().split()))
    a.append(0)
    for x in map(int, input().split()):
        a[-1] = a[-1] * b + x
print('<>='[(a[0] == a[1]) + (a[0] >= a[1])])


import sys
a, b = [int(x) for x in input().split()]
base = b ** (a - 1)
res1 = 0
arr = [int(x) for x in input().split()]
for digit in arr:
    res1 += digit * base
    base //= b

a, b = [int(x) for x in input().split()]
base = b ** (a - 1)
res2 = 0
arr = [int(x) for x in input().split()]
for digit in arr:
    res2 += digit * base
    base //= b

if res1 > res2:
    print('>')
elif res1 < res2:
    print('<')
else:
    print('=')



n,bx = list(map(int, input().split()))
X = list(map(int, input().split()))
m,by = list(map(int, input().split()))
Y = list(map(int, input().split()))

def calcul(n,bx,X):
    r = X[n-1]
    c = 1
    for k in range(2,n+1):
        c *= bx
        r += X[n-k]*c
    return r

x = calcul(n,bx,X)
y = calcul(m,by,Y)
if x==y:
    print("=")
elif x>y:
    print(">")
else:
    print("<")


3

def make_num(lst, bx):
	res = 0
	for elem in lst:
		res *= bx
		res += elem
	return res


n, bx = map(int, input().split())
num1  = make_num(map(int, input().split()), bx)

m, by = map(int, input().split())
num2  = make_num(map(int, input().split()), by)

if num1 < num2:
	print('<')
elif num1 == num2:
	print('=')
else:
	print('>')

n, bx = list(map(int, input().split()))
x = list(map(int, input().split()))
m, by = list(map(int, input().split()))
y = list(map(int, input().split()))
tmp = 1
ans = 0
for i in range(1, n + 1):
    ans += x[-i] * tmp
    tmp *= bx
ans1 = 0
tmp = 1
for i in range(1, m + 1):
    ans1 += y[-i] * tmp
    tmp *= by
if ans < ans1:
    print("<")
elif ans > ans1:
    print(">")
else:
    print("=")



(n, b) = list(map(int, input().split()))
x = list(map(int, input().split()))
(m, c) = list(map(int, input().split()))
y = list(map(int, input().split()))
x = x[::-1]
y = y[::-1]
X = 0
Y = 0
for i in range(len(x)):
    X += x[i] * b ** i
for i in range(len(y)):
    Y += y[i] * c ** i
if (X == Y):
    print("=")
elif (X < Y):
    print("<")
else:
    print(">")


n, bx = list(map(int, input().split()))
b = list(map(int, input().split()))
ansx = 0
for i in range(n - 1, -1, -1):
    ansx += b[i] * bx**(n - i - 1)

m, by = list(map(int, input().split()))
b = list(map(int, input().split()))
ansy = 0
for i in range(m - 1, -1, -1):
    ansy += b[i] * by**(m - i - 1)
if (ansx == ansy):
    print('=')
elif ansx > ansy:
    print('>')
else:
    print('<')


def convert(digits, base):
    res = 0
    digits.reverse()
    power = 1
    for i in digits:
        res += i * power
        power *= base
    return res

n, base_a = [int(x) for x in input().split()]
digits_a = [int(x) for x in input().split()]
a = convert(digits_a, base_a)

n, base_a = [int(x) for x in input().split()]
digits_a = [int(x) for x in input().split()]
b = convert(digits_a, base_a)

if a < b:
    print("<")
elif a > b:
    print(">")
else:
    print("=")


n, bx = list(map(int, input().split()))
x = list(map(int, input().split()))

m, by = list(map(int, input().split()))
y = list(map(int, input().split()))

x = x[::-1]
y = y[::-1]
st = 1
ansx = 0
for i in range(n):
    ansx += x[i] * st
    st *= bx

st = 1
ansy = 0
for i in range(m):
    ansy += y[i] * st
    st *= by

print("=" if ansx == ansy else ("<" if ansx < ansy else ">"))


n, bx = list(map(int,input().split()))

num = list(map(int,input().split()))

num.reverse()

orig = 0
for i in range(0,len(num)):
    orig += num[i]*bx**i


n, bx2 = list(map(int,input().split()))

num = list(map(int,input().split()))

num.reverse()

orig2 = 0
for i in range(0,len(num)):
    orig2 += num[i]*bx2**i


if orig == orig2:
    print('=')
elif orig < orig2:
    print('<')
else:
    print('>')


__author__ = 'cmashinho'

n, b = list(map(int, input().split()))
lB = list(map(int, input().split()))
m, y = list(map(int, input().split()))
lY = list(map(int, input().split()))

nB = 0
nY = 0

for i in range(n):
    nB += lB[i] * int(pow(b, (n - i - 1)))

for i in range(m):
    nY += lY[i] * int(pow(y, (m - i - 1)))

if nB == nY:
    print("=")
elif nB > nY:
    print(">")
else:
    print("<")


n1, b1 = list(map(int, input().split()))
ans1 = 0
a1 = list(map(int, input().split()))
n2, b2 = list(map(int, input().split()))
ans2 = 0
a2 = list(map(int, input().split()))
for i in range(n1):
    ans1 += a1[i] * (b1 ** (n1 - i - 1))
for i in range(n2):
    ans2 += a2[i] * (b2 ** (n2 - i - 1))
if (ans1 == ans2):
    print('=')
else:
    if ans1 > ans2:
        print('>')
    else:
        print('<')


n, xbase = list(map(int, input().split()))
xs = list(map(int, input().split()))

m, ybase = list(map(int, input().split()))
ys = list(map(int, input().split()))

x = 0
xt = 1
for c in xs[::-1]:
	x += c * xt
	xt *= xbase

y = 0
yt = 1
for c in ys[::-1]:
	y += c * yt
	yt *= ybase

if x < y:
	print('<')
elif x > y:
	print('>')
else:
	print('=')


n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
l, k = list(map(int, input().split()))
b = list(map(int, input().split()))
c1 = 0
c2 = 0
for i in range(n - 1, -1, -1):
    c1 += m ** (n - 1 - i) * a[i]
for t in range(l - 1, -1, -1):
    c2 += k ** (l - 1 - t) * b[t]
if c1 == c2:
    print('=')
elif c1 < c2:
    print('<')
else:
    print('>')


firstline = [int(x) for x in input().split()]
firstnum = 0
for digit in input().split():
    firstnum *= firstline[1]
    firstnum += int(digit)

secondline = [int(x) for x in input().split()]
secondnum = 0

for digit in input().split():
    secondnum *= secondline[1]
    secondnum += int(digit)

if (firstnum > secondnum):
    print('>')
if (firstnum == secondnum):
    print('=')
if (firstnum < secondnum):
    print('<')


# import sys
# sys.stdin = open('cf602a.in')

n, bx = map(int, input().split())
x = list(map(int, input().split()))

m, by = map(int, input().split())
y = list(map(int, input().split()))

xx = sum(v * bx**(len(x) - i - 1) for i, v in enumerate(x))
yy = sum(v * by**(len(y) - i - 1) for i, v in enumerate(y))

if xx < yy:
	print('<')
elif xx == yy:
	print('=')
else:
	print('>')

n1 = 0
n, b = list(map(int, input().split()))
a = list(map(int, input().split()))
a.reverse()
for i in range(n):
    n1 += a[i] * (b ** i)
n2 = 0
n, b = list(map(int, input().split()))
a = list(map(int, input().split()))
a.reverse()
for i in range(n):
    n2 += a[i] * (b ** i)
if n1 < n2:
    print("<")
if n1 == n2:
    print("=")
if n1 > n2:
    print(">")


n, b = [int(i) for i in input().split(" ")]
bx = [int(i) for i in input().split(" ")]
m, a = [int(i) for i in input().split(" ")]
ax = [int(i) for i in input().split(" ")]
bb, aa = 0, 0
for i in bx:
    aa = aa * b + i
for i in ax:
    bb = bb * a + i
if aa < bb:
    print('<')
elif aa == bb:
    print('=')
else:
    print('>')


z1 = list(map(int,input().split()))
x = list(map(int,input().split()))
z2 = list(map(int,input().split()))
y= list(map(int,input().split()))

n1, b1 = z1[0],z1[1]
n2, b2 = z2[0],z2[1]

ansx = ansy = 0

for i in range(n1):
    ansx+= x[n1-i-1]*(b1**i)
for i in range(n2):
    ansy+= y[n2-i-1]*(b2**i)
    
if ansx == ansy:
    print('=')
elif ansx > ansy:
    print('>')
else:
    print('<')
    


"""
Codeforces Round 333 (Div. 2)

Problem 602 A.

@author yamaton
@date 2015-11-24
"""

import itertools as it
import functools
import operator
import collections
import math
import sys


def solve(xs, ys, bx, by):
    x = functools.reduce(lambda acc, x: acc * bx + x, xs)
    y = functools.reduce(lambda acc, y: acc * by + y, ys)
    if x < y:
        return '<'
    elif x > y:
        return '>'
    else:
        return '='



# def p(*args, **kwargs):
#     return print(*args, file=sys.stderr, **kwargs)


def main():
    [n, bx] = list(map(int, input().strip().split()))
    xs = [int(c) for c in input().strip().split()]
    assert len(xs) == n
    [m, by] = list(map(int, input().strip().split()))
    ys = [int(c) for c in input().strip().split()]
    assert len(ys) == m

    result = solve(xs, ys, bx, by)
    print(result)


def __starting_point():
    main()

__starting_point()