#include <bits/stdc++.h>
using namespace std;
int main() {
  int digit, base, pos, n;
  long long int sum = 0, sum_1 = 0, weight;
  cin >> digit >> base;
  pos = digit - 1;
  for (int i = 0; i < digit; i++, pos--) {
    cin >> n;
    weight = base;
    if (pos == 0) weight = 1;
    for (int j = 1; j < pos; j++) {
      weight *= base;
    }
    sum += n * weight;
  }
  cin >> digit >> base;
  pos = digit - 1;
  for (int i = 0; i < digit; i++, pos--) {
    cin >> n;
    weight = base;
    if (pos == 0) weight = 1;
    for (int j = 1; j < pos; j++) {
      weight *= base;
    }
    sum_1 += n * weight;
  }
  if (sum == sum_1)
    cout << "=" << endl;
  else if (sum > sum_1)
    cout << ">" << endl;
  else
    cout << "<" << endl;
  return 0;
}
