#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, g[3005 * 3005], x, y, z, A[3005][3005], ans;
deque<long long> q;
vector<long long> v;
vector<vector<long long> > V;
vector<long long> fun(vector<long long> v, long long n, long long b) {
  vector<long long> ans;
  q.clear();
  for (__typeof((b)) i = (0); i < (b); i++) {
    while ((long long)q.size() && v[i] <= v[q.back()]) q.pop_back();
    q.push_back(i);
  }
  ans.push_back(v[q.front()]);
  for (__typeof((n)) i = (b); i < (n); i++) {
    while ((long long)q.size() && q.front() <= i - b) q.pop_front();
    while ((long long)q.size() && v[i] <= v[q.back()]) q.pop_back();
    q.push_back(i);
    ans.push_back(v[q.front()]);
  }
  return ans;
}
void solve() {
  cin >> n >> m >> a >> b >> g[0] >> x >> y >> z;
  for (__typeof((3005 * 3005)) i = (1); i < (3005 * 3005); i++)
    g[i] = (g[i - 1] * x + y) % z;
  for (__typeof((n + 1)) i = (1); i < (n + 1); i++) {
    for (__typeof((m + 1)) j = (1); j < (m + 1); j++)
      A[i][j] = g[(i - 1) * m + j - 1];
  }
  for (__typeof((n + 1)) i = (1); i < (n + 1); i++) {
    v.clear();
    for (__typeof((m + 1)) j = (1); j < (m + 1); j++) v.push_back(A[i][j]);
    V.push_back(fun(v, m, b));
  }
  for (__typeof(((long long)V[0].size())) j = (0); j < ((long long)V[0].size());
       j++) {
    v.clear();
    for (__typeof((n)) i = (0); i < (n); i++) v.push_back(V[i][j]);
    vector<long long> res = fun(v, n, a);
    for (auto i : res) ans += i;
  }
  {
    cout << ans << "\n";
    return;
  };
}
void prep() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  prep();
  cout << fixed << setprecision(12);
  while (t--) solve();
  return 0;
}
