#include <bits/stdc++.h>
using namespace std;
long long int sum1, sum2;
int main() {
  long long int digit, base, tmp, sum;
  scanf("%I64d %I64d", &digit, &base);
  for (int i = 1; i <= digit; i++) {
    scanf("%I64d", &tmp);
    sum1 = sum1 * base + tmp;
  }
  scanf("%I64d %I64d", &digit, &base);
  for (int i = 1; i <= digit; i++) {
    scanf("%I64d", &tmp);
    sum2 = sum2 * base + tmp;
  }
  sum1 == sum2 ? putchar('=') : sum1 > sum2 ? putchar('>') : putchar('<');
  return 0;
}
