#include <bits/stdc++.h>
using namespace std;
int abs(int a) { return a < 0 ? -1 * a : a; }
void solve() {
  int n, m, bx, by;
  cin >> n >> bx;
  int x[n];
  for (int i = 0; i < n; i++) cin >> x[i];
  cin >> m >> by;
  int y[m];
  for (int i = 0; i < m; i++) cin >> y[i];
  long long X = 0, Y = 0;
  for (int i = n - 1; i >= 0; i--) {
    X = X + x[i] * pow(bx, n - i - 1);
  }
  for (int i = m - 1; i >= 0; i--) {
    Y = Y + y[i] * pow(by, m - i - 1);
  }
  if (X == Y) {
    cout << "=";
    return;
  } else if (X > Y) {
    cout << ">";
    return;
  }
  cout << "<";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  solve();
  return 0;
}
