#include <bits/stdc++.h>
using namespace std;
long long int sum1, sum2;
inline void in(long long int &_8) {
  long long int _6 = 1;
  char _0;
  while (((_0 = getchar()) < '0' || _0 > '9') && _0 != '-')
    ;
  _0 == '-' ? (_6 = -1, _8 = 0) : (_8 = _0 - '0');
  while ((_0 = getchar()) >= '0' && _0 <= '9') _8 = _8 * 10 + _0 - '0';
  _8 *= _6;
}
int main() {
  long long int digit, base, tmp, sum;
  in(digit);
  in(base);
  for (int i = 1; i <= digit; i++) {
    in(tmp);
    sum1 = sum1 * base + tmp;
  }
  in(digit);
  in(base);
  for (int i = 1; i <= digit; i++) {
    in(tmp);
    sum2 = sum2 * base + tmp;
  }
  sum1 == sum2 ? putchar('=') : sum1 > sum2 ? putchar('>') : putchar('<');
  return 0;
}
