#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto v : vec) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec) {
  os << "deq[";
  for (auto v : vec) os << v << ",";
  os << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
  os << "(" << pa.first << "," << pa.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
  os << "{";
  for (auto v : mp) os << v.first << "=>" << v.second << ",";
  os << "}";
  return os;
}
template <typename T>
void ndarray(vector<T> &vec, int len) {
  vec.resize(len);
}
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
  vec.resize(len);
  for (auto &v : vec) ndarray(v, args...);
}
template <typename T>
bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T>
bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
  return make_pair(l.first - r.first, l.second - r.second);
}
int N, M, A, B;
lint g0, X, Y, Z;
vector<vector<lint>> solve(const vector<vector<lint>> &M, int a) {
  int H = M.size(), W = M[0].size();
  vector<vector<lint>> ret;
  ndarray(ret, H, W - a + 1);
  for (int h = (0), h_end_ = (H); h < h_end_; h++) {
    deque<int> deq;
    for (int w = (0), w_end_ = (a - 1); w < w_end_; w++) {
      while (!deq.empty() and M[h][deq.back()] >= M[h][w]) deq.pop_back();
      deq.push_back(w);
    }
    for (int w = (a - 1), w_end_ = (W); w < w_end_; w++) {
      while (!deq.empty() and M[h][deq.back()] >= M[h][w]) deq.pop_back();
      deq.push_back(w);
      ret[h][w - a + 1] = M[h][deq.front()];
      if (deq.front() == w - a + 1) deq.pop_front();
    }
  }
  return ret;
}
vector<vector<lint>> transpose(const vector<vector<lint>> &H) {
  int N = H.size(), M = H[0].size();
  vector<vector<lint>> ret;
  ndarray(ret, M, N);
  for (int i = (0), i_end_ = (N); i < i_end_; i++)
    for (int j = (0), j_end_ = (M); j < j_end_; j++) ret[j][i] = H[i][j];
  return ret;
}
int main() {
  cin >> N >> M >> A >> B >> g0 >> X >> Y >> Z;
  vector<vector<lint>> H;
  ndarray(H, N, M);
  H[0][0] = g0;
  for (int i = (1), i_end_ = (N * M); i < i_end_; i++)
    H[i / M][i % M] = (H[(i - 1) / M][(i - 1) % M] * X + Y) % Z;
  H = solve(H, B);
  H = transpose(H);
  H = solve(H, A);
  lint ret = 0;
  for (auto vec : H)
    for (auto v : vec) ret += v;
  cout << ret << endl;
}
