#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1677721600")
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double ee = exp(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
const double pi = acos(-1.0);
int readT() {
  char c;
  int ret = 0, flg = 0;
  while (c = getchar(), (c < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    flg = 1;
  else
    ret = c ^ 48;
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c ^ 48);
  return flg ? -ret : ret;
}
long long readTL() {
  char c;
  int flg = 0;
  long long ret = 0;
  while (c = getchar(), (c < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    flg = 1;
  else
    ret = c ^ 48;
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c ^ 48);
  return flg ? -ret : ret;
}
long long mypow(int a, int t) {
  long long res = 1;
  for (int i = (1); i <= (t); i++) {
    res *= a;
  }
  return res;
}
int main() {
  int n = readT();
  int b1 = readT();
  long long ansb1 = 0;
  for (int i = (0); i <= (n - 1); i++) {
    long long t = readTL();
    ansb1 += t * mypow(b1, n - i - 1);
  }
  int n2 = readT();
  int b2 = readT();
  long long ansb2 = 0;
  for (int i = (0); i <= (n2 - 1); i++) {
    long long t = readTL();
    ansb2 += t * mypow(b2, n2 - i - 1);
  }
  if (ansb1 == ansb2)
    puts("=");
  else if (ansb1 < ansb2)
    puts("<");
  else
    puts(">");
  return 0;
}
