#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


int dp[2][101][1001];
int sopt[1001], opt[1001];
const int INF = 1000000;
void dpru(int n, int low, int upper, int limit, int* e, int*s, int* opt)
{
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j <= upper; ++j)
			for (int k = 0; k <= limit; ++k)
				dp[i][j][k] = -INF;
	dp[0][0][0] = 0;

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j <= upper; ++j)
		{
			for (int k = 0; k <= limit; ++k)
			{
				dp[(i+1)&1][j][k] = max(dp[(i+1)&1][j][k], dp[i&1][j][k]);
				if (k + e[i] <= limit)
					dp[(i+1)&1][j+1][k+e[i]] = max(dp[(i+1)&1][j+1][k+e[i]], dp[i&1][j][k] + s[i]);
			}
		}
	}

	for (int i = 0; i <= limit; ++i)
	{
		opt[i] = -INF;
		for (int j = low; j <= upper; ++j)
			opt[i] = max(opt[i], dp[n&1][j][i]);
	}
}
int main()
{
	int limit, n, m, x;
	while (cin >> limit >> n >> m >> x, limit | n | m | x)
	{
		string hoge;
		int se[100], ss[100], e[100], s[100];
		for (int i = 0; i < n; ++i)
			cin >> hoge >> se[i] >> ss[i];
		for (int i = 0; i < m; ++i)
			cin >> hoge >> e[i] >> s[i];

		dpru(n, 1, 2, limit, se, ss, sopt);
		dpru(m, x, m, limit, e, s, opt);

		int res = 0;
		for (int i = 0; i <= limit; ++i)
			for (int j = 0; i+j <= limit; ++j)
				res = max(res, sopt[i] + opt[j]);

		cout << res << endl;
	}

	return 0;
}