#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int limit, n, m, x;
        cin >> limit >> n >> m >> x;
        if(limit == 0)
            return 0;

        vector<vector<int> > dp(limit+1, vector<int>(x+1, -1));
        vector<int> a(n), b(n);
        for(int i=0; i<n; ++i){
            string s;
            cin >> s >> a[i] >> b[i];
            if(a[i] <= limit)
                dp[a[i]][0] = max(dp[a[i]][0], b[i]);

            for(int j=0; j<i; ++j){
                if(a[i] + a[j] <= limit)
                    dp[a[i]+a[j]][0] = max(dp[a[i]+a[j]][0], b[i]+b[j]);
            }
        }

        for(int i=0; i<m; ++i){
            string s;
            int c, d;
            cin >> s >> c >> d;
            for(int j=limit-c; j>=0; --j){
                for(int k=0; k<=x; ++k){
                    if(dp[j][k] == -1)
                        continue;
                    dp[j+c][min(k+1,x)] = max(dp[j+c][min(k+1,x)], dp[j][k]+d);
                }
            }
        }

        int ret = 0;
        for(int i=0; i<=limit; ++i)
            ret = max(ret, dp[i][x]);
        cout << ret << endl;
    }
}