#include <bits/stdc++.h>
using namespace std;
unsigned long long pow(int a, int b) {
  unsigned long long w = 1;
  for (int i = 1; i <= b; i++) w *= (unsigned long long)a;
  return w;
}
int main() {
  unsigned long long w1 = 0, w2 = 0;
  int n, b;
  scanf("%d%d", &n, &b);
  unsigned long long w = pow(b, n - 1);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    w1 += (unsigned long long)a * w;
    w /= b;
  }
  scanf("%d%d", &n, &b);
  w = pow(b, n - 1);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    w2 += (unsigned long long)a * w;
    w /= b;
  }
  if (w1 < w2)
    printf("<\n");
  else if (w1 > w2)
    printf(">\n");
  else
    printf("=\n");
  return 0;
}
