#include <bits/stdc++.h>
int main(void) {
  int n, m, x, y, temp;
  long long X = 0, Y = 0;
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; i++) {
    X *= x;
    scanf("%d", &temp);
    X += temp;
  }
  scanf("%d %d", &m, &y);
  for (int i = 0; i < m; i++) {
    Y *= y;
    scanf("%d", &temp);
    Y += temp;
  }
  if (X == Y)
    puts("=");
  else
    puts(X > Y ? ">" : "<");
  return 0;
}
