#include <bits/stdc++.h>
using namespace std;
long long int arx[105], ary[105], nx, bx, ny, by, sumx, sumy;
int main() {
  scanf("%lld %lld", &nx, &bx);
  for (int i = 1; i <= nx; i++) {
    scanf("%lld", arx + i);
  }
  long long int t = 1;
  for (int i = 1; i <= nx; i++) {
    sumx += t * arx[nx - i + 1];
    t *= bx;
  }
  scanf("%lld %lld", &ny, &by);
  for (int i = 1; i <= ny; i++) {
    scanf("%lld", ary + i);
  }
  t = 1;
  for (int i = 1; i <= ny; i++) {
    sumy += t * ary[ny - i + 1];
    t *= by;
  }
  if (sumx == sumy)
    puts("=");
  else if (sumx > sumy)
    puts(">");
  else
    puts("<");
}
