#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); }
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const double eps = 1e-6;
long long a[15], b[15];
int n, m, bx, by;
long long pw(int aa, int bb) {
  long long sum = 1;
  for (int i = 0; i < bb; i++) sum *= (long long)aa;
  return sum;
}
long long conv(int f, int base) {
  long long sum = 0;
  if (f == 1) {
    for (int i = n - 1, j = 0; i >= 0; i--, j++) sum += a[i] * pw(base, j);
  } else {
    for (int i = m - 1, j = 0; i >= 0; i--, j++) sum += b[i] * pw(base, j);
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> bx;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> m >> by;
  for (int i = 0; i < m; i++) cin >> b[i];
  long long res = conv(1, bx);
  long long res2 = conv(0, by);
  if (res > res2)
    cout << ">" << endl;
  else if (res < res2)
    cout << "<" << endl;
  else
    cout << "=" << endl;
  return 0;
}
