#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int LIMIT,N,M,X;
int dp_sec[3][21],next_sec[3][21];
int dp_stan[101][1001],next_stan[101][1001];

struct Info{
	int cost,value;
};

struct Data{
	Data(int arg_num,int arg_cost){
		num = arg_num;
		cost = arg_cost;
	}
	int num,cost;
};

void func(){

	Info sec[N];

	char buf[31];

	for(int i = 0; i < N; i++){
		scanf("%s %d %d",buf,&sec[i].cost,&sec[i].value);
	}

	for(int num = 0; num <= 2; num++){
		for(int total_cost = 0; total_cost <= 20; total_cost++){
			dp_sec[num][total_cost] = -1;
			next_sec[num][total_cost] = -1;
		}
	}

	dp_sec[0][0] = 0;
	next_sec[0][0] = 0;

	vector<Data> Updated;

	for(int i = 0; i < N; i++){

		for(int num = 0; num <= 1; num++){
			for(int total_cost = 0; total_cost+sec[i].cost <= 20; total_cost++){
				if(dp_sec[num][total_cost] == -1)continue;

				if(next_sec[num+1][total_cost+sec[i].cost] < dp_sec[num][total_cost]+sec[i].value){
					next_sec[num+1][total_cost+sec[i].cost] = dp_sec[num][total_cost]+sec[i].value;
					Updated.push_back(Data(num+1,total_cost+sec[i].cost));
				}
			}
		}

		for(int k = 0; k < Updated.size(); k++){
			dp_sec[Updated[k].num][Updated[k].cost] = next_sec[Updated[k].num][Updated[k].cost];
		}
		Updated.clear();
	}

	Info stan[M];
	int cost_sum = 0;

	for(int i = 0; i < M; i++){
		scanf("%s %d %d",buf,&stan[i].cost,&stan[i].value);
		cost_sum += stan[i].cost;
	}

	for(int num = 0; num <= M; num++){
		for(int total_cost = 0; total_cost <= 1000; total_cost++){
			dp_stan[num][total_cost] = -1;
			next_stan[num][total_cost] = -1;
		}
	}

	dp_stan[0][0] = 0;
	next_stan[0][0] = 0;
	Updated.clear();

	for(int i = 0; i < M; i++){ //100

		for(int num = 0; num <= M-1; num++){ //100
			for(int total_cost = 0; total_cost+stan[i].cost <= cost_sum; total_cost++){ //1000
				if(dp_stan[num][total_cost] == -1)continue;

				if(next_stan[num+1][total_cost+stan[i].cost] < dp_stan[num][total_cost]+stan[i].value){
					next_stan[num+1][total_cost+stan[i].cost] = dp_stan[num][total_cost]+stan[i].value;
					Updated.push_back(Data(num+1,total_cost+stan[i].cost));
				}
			}
		}

		for(int k = 0; k < Updated.size(); k++){
			dp_stan[Updated[k].num][Updated[k].cost] = next_stan[Updated[k].num][Updated[k].cost];
		}
		Updated.clear();
	}

	int ans = 0;

	for(int sec_num = 1; sec_num <= 2; sec_num++){
		for(int sec_cost = 0; sec_cost <= 20; sec_cost++){
			if(dp_sec[sec_num][sec_cost] == -1)continue;
			for(int stan_num = X; stan_num <= M; stan_num++){
				for(int stan_cost = 0; stan_cost <= LIMIT; stan_cost++){
					if(dp_stan[stan_num][stan_cost] == -1)continue;
					if(sec_cost+stan_cost > LIMIT)continue;

					ans = max(ans,dp_sec[sec_num][sec_cost]+dp_stan[stan_num][stan_cost]);
				}
			}
		}
	}

	printf("%d\n",ans);
}

int main(){

	while(true){
		scanf("%d %d %d %d",&LIMIT,&N,&M,&X);
		if(LIMIT == 0 && N == 0 && M == 0 && X == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 4084