#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline long long input() {
  long long n;
  cin >> n;
  return n;
}
long long pw(long long a, long long b) {
  return (!b ? 1 : (b & 1 ? a * pw(a * a, b / 2) : pw(a * a, b / 2)));
}
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const long long INF = 8e18;
int v[44], v2[44];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n1, x, n2, y;
  long long ans1 = 0, ans2 = 0;
  cin >> n1 >> x;
  long long t = 1, t2 = 1;
  for (int i = n1 - 1; i >= 0; i--) {
    cin >> v[i];
  }
  for (int i = 0; i < n1; i++) {
    ans1 += t * v[i];
    t *= x;
  }
  cin >> n2 >> y;
  for (int i = n2 - 1; i >= 0; i--) {
    cin >> v2[i];
  }
  for (int i = 0; i < n2; i++) {
    ans2 += t2 * v2[i];
    t2 *= y;
  }
  if (ans1 == ans2) {
    cout << "=";
  } else if (ans1 > ans2) {
    cout << ">";
  } else {
    cout << "<";
  }
  return 0;
}
