#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long fun(int n, int base) {
  vector<int> v(n);
  for (auto& i : v) cin >> i;
  long long res = 0;
  for (int i = n - 1; i >= 0; i--) {
    res += pow(base, n - i - 1) * v[i];
  }
  return res;
}
int main() {
  int x, bx;
  cin >> x >> bx;
  long long sumX = fun(x, bx);
  int y, by;
  cin >> y >> by;
  long long sumY = fun(y, by);
  if (sumX == sumY)
    cout << "=";
  else
    cout << (sumX > sumY ? '>' : '<');
  return 0;
}
