#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Unit {
long long a;
long long b;
int c;
};
struct EnemyType {
long long d;
long long e;
};
struct State {
int killed;
long long damage;
bool operator<(const State& other) const {
if (killed != other.killed) {
return killed < other.killed;
}
return damage < other.damage;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m, n, k, f;
if (!(cin >> m >> n >> k >> f)) return 0;
vector<Unit> units(m);
for (int i = 0; i < m; ++i) {
cin >> units[i].a >> units[i].b >> units[i].c;
}
vector<EnemyType> wave_pattern(n);
for (int i = 0; i < n; ++i) {
cin >> wave_pattern[i].d >> wave_pattern[i].e;
}
long long total_enemies = (long long)n * f;
vector<State> dp(k + 1, {-1, -1});
dp[0] = {0, 0};
for (int c = 0; c <= k; ++c) {
if (dp[c].killed == -1) continue;
if (dp[c].killed >= total_enemies) {
cout << c << endl;
return 0;
}
for (const auto& unit : units) {
if (c + unit.c > k) continue;
int curr_killed = dp[c].killed;
long long curr_dmg = dp[c].damage;
long long hero_hp = unit.b;
while (curr_killed < total_enemies && hero_hp > 0) {
const EnemyType& enemy_stats = wave_pattern[curr_killed % n];
long long enemy_hp = enemy_stats.e - curr_dmg;
long long turns_to_kill_enemy = (enemy_hp + unit.a - 1) / unit.a;
long long turns_to_kill_hero = 1e18;
if (enemy_stats.d > 0) {
turns_to_kill_hero = (hero_hp + enemy_stats.d - 1) / enemy_stats.d;
}
long long turns = min(turns_to_kill_enemy, turns_to_kill_hero);
long long dmg_dealt = turns * unit.a;
long long dmg_taken = turns * enemy_stats.d;
curr_dmg += dmg_dealt;
hero_hp -= dmg_taken;
bool enemy_dead = (curr_dmg >= enemy_stats.e);
bool hero_dead = (hero_hp <= 0);
if (enemy_dead) {
curr_killed++;
curr_dmg = 0;
}
if (hero_dead) {
break;
}
}
int next_cost = c + unit.c;
State new_state = {curr_killed, curr_dmg};
if (dp[next_cost] < new_state) {
dp[next_cost] = new_state;
}
}
}
for(int c = 0; c <= k; ++c) {
if(dp[c].killed >= total_enemies) {
cout << c << endl;
return 0;
}
}
cout << "-1" << endl;
return 0;
}