#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
int n, m;
long long bn, bm, l1 = 1, l2 = 1, ans1, ans2;
long long arr1[MAXN], arr2[MAXN];
int main() {
  cin >> n >> bn;
  for (int i = 0; i < n; i++) cin >> arr1[i];
  for (int i = n - 1; i >= 0; i--) ans1 += l1 * arr1[i], l1 *= bn;
  cin >> m >> bm;
  for (int i = 0; i < m; i++) cin >> arr2[i];
  for (int i = m - 1; i >= 0; i--) ans2 += l2 * arr2[i], l2 *= bm;
  ;
  if (ans1 < ans2) cout << "<";
  if (ans1 == ans2) cout << "=";
  if (ans1 > ans2) cout << ">";
  return 0;
}
