#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
int main() {
  int n1, b1;
  scanf("%d%d", &n1, &b1);
  long long x = 0;
  for (int i = 0, _n = n1; i < _n; i++) {
    x *= b1;
    int tr;
    scanf("%d", &tr);
    x += tr;
  }
  int n2, b2;
  scanf("%d%d", &n2, &b2);
  long long y = 0;
  for (int i = 0, _n = n2; i < _n; i++) {
    y *= b2;
    int tr;
    scanf("%d", &tr);
    y += tr;
  }
  if (x == y) printf("=\n");
  if (x < y) printf("<\n");
  if (x > y) printf(">\n");
  return 0;
}
