#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-12;
double __t;
void quit();
long long a, b;
int n, bas;
int main() {
  cin >> n >> bas;
  long long t = 1;
  for (int i = 0; i < (int)n - 1; i++) t *= bas;
  int t1;
  for (int i = 0; i < (int)n; i++) {
    cin >> t1;
    a += t * t1;
    t /= bas;
  }
  cin >> n >> bas;
  t = 1;
  for (int i = 0; i < (int)n - 1; i++) t *= bas;
  for (int i = 0; i < (int)n; i++) {
    cin >> t1;
    b += t * t1;
    t /= bas;
  }
  if (a == b)
    cout << "=\n";
  else if (a > b)
    cout << ">\n";
  else
    cout << "<\n";
  quit();
}
void quit() { exit(0); }
