#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 = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const long long INF = 8e18;
int n, m, k, p;
long long T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];
bool f(long long q) {
  long long cnt = 0;
  fill(ans, ans + MAXN, 0);
  fill(T, T + MAXN, 0);
  fill(mod, mod + MAXN, 0);
  for (int i = 0; i < n; i++) {
    long long LAST = m * a[i] + h[i];
    if (LAST > q) {
      mod[i] = (LAST - q) % p;
      T[i] = ((LAST - q + p - 1) / p);
    } else {
      T[i] = 0;
      mod[i] = 0;
    }
    cnt += (T[i]);
  }
  if (cnt > m * k) return 0;
  for (int i = 0; i < n; i++) {
    if (T[i] == 0) continue;
    long long pd = 0, Re = h[i];
    for (int j = 0; j < T[i]; j++) {
      long long nd = (p - Re % p + a[i] - 1) / a[i] + pd, nh = nd * a[i] + h[i];
      if (j == 0) {
        if (Re >= mod[i]) {
          nd = pd;
          nh = Re;
        } else {
          nd = (mod[i] - Re + a[i] - 1) / a[i];
          nh = nd * a[i] + h[i];
        }
      } else if (Re >= (j + 1) * p) {
        nd = pd;
        nh = Re;
      }
      Re = nh;
      pd = nd;
      ans[pd]++;
      if (pd >= m) {
        return 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (ans[i] > k) {
      ans[i + 1] += (ans[i] - k);
    }
  }
  if (ans[m] == 0) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> k >> p;
  long long MAX = 0;
  for (int i = 0; i < n; i++) {
    cin >> h[i] >> a[i];
    MAX = max(MAX, a[i]);
  }
  long long d = 0, up = 1e15;
  while (up - d > 1) {
    long long mid = (up + d) / 2;
    if (f(mid)) {
      up = mid;
    } else {
      d = mid;
    }
  }
  cout << up;
  return 0;
}
