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