#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, base, number1 = 0, number2 = 0;
  int temp;
  vector<int> numbers;
  cin >> n >> base;
  while (n--) cin >> temp, numbers.insert(numbers.begin(), temp);
  for (long long int i = 0, j = 1; i < numbers.size(); i++, j *= base)
    number1 += j * numbers[i];
  numbers.clear();
  cin >> n >> base;
  while (n--) cin >> temp, numbers.insert(numbers.begin(), temp);
  for (long long int i = 0, j = 1; i < numbers.size(); i++, j *= base)
    number2 += j * numbers[i];
  if (number1 == number2)
    cout << "=" << endl;
  else if (number1 < number2)
    cout << "<" << endl;
  else
    cout << ">" << endl;
  return 0;
}
