#include <bits/stdc++.h>
int main() {
  int n, b;
  int data[10];
  unsigned long long v1 = 0, v2 = 0;
  int i;
  unsigned long long mul;
  scanf("%d", &n);
  scanf("%d", &b);
  for (i = 0; i < n; i++) scanf("%d", &data[i]);
  mul = 1;
  for (i = n - 1; i >= 0; i--) {
    v1 += mul * data[i];
    mul *= b;
  }
  scanf("%d", &n);
  scanf("%d", &b);
  for (i = 0; i < n; i++) scanf("%d", &data[i]);
  mul = 1;
  for (i = n - 1; i >= 0; i--) {
    v2 += mul * data[i];
    mul *= b;
  }
  if (v1 > v2) printf(">");
  if (v1 == v2) printf("=");
  if (v1 < v2) printf("<");
}
