#include <bits/stdc++.h>
using namespace std;
int main() {
  int size1, base1, size2, base2;
  cin >> size1 >> base1;
  int num1[size1];
  for (int i = 0; i < size1; i++) cin >> num1[i];
  cin >> size2 >> base2;
  int num2[size2];
  for (int i = 0; i < size2; i++) cin >> num2[i];
  long long int base_temp = 1;
  long long int num1_end = 0;
  for (int i = size1 - 1; i > -1; i--) {
    num1_end += num1[i] * base_temp;
    base_temp *= base1;
  }
  base_temp = 1;
  long long int num2_end = 0;
  for (int i = size2 - 1; i > -1; i--) {
    num2_end += num2[i] * base_temp;
    base_temp *= base2;
  }
  if (num1_end > num2_end)
    cout << ">";
  else if (num1_end < num2_end)
    cout << "<";
  else
    cout << "=";
  return 0;
}
