#include <bits/stdc++.h>
using namespace std;
int c[1000];
int main() {
  long long a = 0, b = 0, j = 1;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = n; i >= 1; i--) scanf("%d", &c[i]);
  for (int i = 1; i <= n; i++) {
    a += c[i] * j;
    j *= m;
  }
  scanf("%d%d", &n, &m);
  for (int i = n; i >= 1; i--) scanf("%d", &c[i]);
  j = 1;
  for (int i = 1; i <= n; i++) {
    b += j * c[i];
    j *= m;
  }
  if (a > b)
    printf(">");
  else if (a == b)
    printf("=");
  else
    printf("<");
  return 0;
}
