#include <bits/stdc++.h>
using namespace std;
int main() {
  int nx, ny, bx, by;
  long long x = 0, y = 0;
  cin >> nx >> bx;
  long long o = 1;
  for (int i = 1; i < nx; i++) {
    o *= bx;
  }
  for (int i = nx - 1; i >= 0; i--) {
    int l;
    cin >> l;
    x += l * o;
    o /= bx;
  }
  cin >> ny >> by;
  o = 1;
  for (int i = 1; i < ny; i++) {
    o *= by;
  }
  for (int i = ny - 1; i >= 0; i--) {
    int l;
    cin >> l;
    y += l * o;
    o /= by;
  }
  if (x < y) {
    cout << "<";
  } else if (x > y) {
    cout << ">";
  } else {
    cout << "=";
  }
  return 0;
}
