#include <bits/stdc++.h>
const int inf_int = 2e9;
const long long inf_ll = 2e18;
const int maxn = 5e2 + 10;
using namespace std;
inline int read() {
  int ra, fh;
  char rx;
  rx = getchar(), ra = 0, fh = 1;
  while ((rx < '0' || rx > '9') && rx != '-') rx = getchar();
  if (rx == '-') fh = -1, rx = getchar();
  while (rx >= '0' && rx <= '9') ra *= 10, ra += rx - 48, rx = getchar();
  return ra * fh;
}
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qpow(long long p, long long q) {
  long long f = 1;
  while (q) {
    if (q & 1) f = f * p;
    p = p * p;
    q >>= 1;
  }
  return f;
}
int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int N = 1e7 + 5;
long long a, b;
int n, x, m, y, t;
vector<int> aa, bb;
int main() {
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> t;
    aa.push_back(t);
  }
  cin >> m >> y;
  for (int i = 1; i <= m; i++) {
    cin >> t;
    bb.push_back(t);
  }
  long long tt = 1;
  for (int i = n - 1; i >= 0; i--) {
    a += tt * aa[i];
    tt *= x;
  }
  tt = 1;
  for (int i = m - 1; i >= 0; i--) {
    b += tt * bb[i];
    tt *= y;
  }
  if (a == b) {
    cout << "=" << endl;
  } else if (a > b) {
    cout << ">" << endl;
  } else
    cout << "<" << endl;
  return 0;
}
