#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
void Main() {
  int n, u, k, hq;
  cin >> n >> u >> k >> hq;
  struct ly {
    int hacked = 0, hack = 0, blood = 0, sy;
    bool alive() { return blood; }
    bool chk(int k) { return hacked <= k; }
    void attack(int a, int mx) {
      if (!alive() || hacked > mx) {
        return;
      }
      if (hacked) {
        ++hacked;
        blood = max(blood - (a >> 1), 0ll);
      } else {
        ++hacked;
        blood = max(blood - a, 0ll);
      }
    }
    bool operator<(ly b) const {
      if (blood != b.blood) {
        return blood < b.blood;
      } else if (hack != b.hack) {
        return hack < b.hack;
      } else {
        return sy < b.sy;
      }
    }
  };
  vector<ly> enemy(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> enemy[i].hack >> enemy[i].blood;
    enemy[i].sy = i;
  }
  set<ly> pq;
  set<ly> lv;
  for (int i = 1; i <= n; ++i) {
    pq.insert(enemy[i]);
    lv.insert(enemy[i]);
  }
  while (lv.size() && hq) {
    auto tmp = *pq.begin(), c = tmp;
    tmp.attack(u, k);
    if (!tmp.alive()) {
      if (pq.count(c))
        pq.erase(c);
      if (lv.count(c))
        lv.erase(c);
    } else if (!tmp.chk(k)) {
      if (pq.count(c))
        pq.erase(c);
    }
    if (lv.size())
      hq = max(hq - ((*lv.rbegin()).hack), 0ll);
  }
  cout << n - lv.size() << endl;
}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    Main();
  }
  return 0;
}