#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
int n, m, a, b, s[MaxN + 5], p[MaxN + 5];
long long ans1, ans2, x, y;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  scanf("%d%d", &a, &b);
  for (int i = 1; i <= a; i++) scanf("%d", &p[i]);
  ans1 += s[n];
  ans2 += p[a];
  for (int i = n - 1; i >= 1; i--) {
    ++x;
    y = 1;
    for (int j = 1; j <= x; j++) y *= m;
    ans1 += y * s[i];
  }
  x = 0;
  for (int i = a - 1; i >= 1; i--) {
    ++x;
    y = 1;
    for (int j = 1; j <= x; j++) y *= b;
    ans2 += y * p[i];
  }
  if (ans1 > ans2) printf(">");
  if (ans1 == ans2) printf("=");
  if (ans1 < ans2) printf("<");
}
