#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b % 2 == 1) ans = ans * a;
    b = b / 2;
    a = a * a;
  }
  return ans;
}
int main() {
  long long int first = 0, second = 0;
  long long int n, b;
  scanf("%lld %lld", &n, &b);
  long long int A[100];
  for (int i = 0; i < n; i++) {
    scanf("%lld", &A[i]);
  }
  long long int j = 0;
  for (int i = n - 1; i >= 0; i--) {
    first = first + power(b, j++) * A[i];
  }
  scanf("%lld %lld", &n, &b);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &A[i]);
  }
  j = 0;
  for (int i = n - 1; i >= 0; i--) {
    second = second + power(b, j++) * A[i];
  }
  if (first == second)
    printf("=\n");
  else if (first > second)
    printf(">\n");
  else
    printf("<\n");
}
