#include <bits/stdc++.h>
int x[10], y[10];
int main() {
  int n, m, bx, by;
  long long xx, yy, b;
  scanf("%d%d", &n, &bx);
  for (int i = n - 1; i >= 0; i--) scanf("%d", &x[i]);
  scanf("%d%d", &m, &by);
  for (int i = m - 1; i >= 0; i--) scanf("%d", &y[i]);
  xx = 0LL;
  b = 1LL;
  for (int i = 0; i < n; i++) {
    xx += b * x[i];
    b *= bx;
  }
  yy = 0LL;
  b = 1LL;
  for (int i = 0; i < m; i++) {
    yy += b * y[i];
    b *= by;
  }
  if (xx == yy)
    puts("=");
  else if (xx < yy)
    puts("<");
  else
    puts(">");
  return 0;
}
