Problem: Izua University Elementary School is famous as one of Japan's leading competition programmer training schools. The teachers at this school have a wide range of algorithmic knowledge and utilize it on a daily basis. As a teacher, you will be in charge of drawing and crafting classes this year. In this class, all children are supposed to complete one task in one year. The outline of the class is as follows.

* There are D lessons in a year (no lessons more than once on the same day), all of which are devoted to assignment production.
* There are M types of assignments to create.
* Assign one task from M types to each child.
* There are N children, and each of them is assigned a different task.



Children use several of the K types of parts to complete the task. The outline of the assignment production is as follows.

* The type and number of parts to be used are predetermined for each task.
* The type and number of parts used to complete the task must match the type and number of parts used in the task in just proportion.
* For different tasks, the types and numbers of parts used may all be the same.
* For each task, only two parts of the same type can be used.
* The order in which the parts are used does not affect the completion of the task.
* P bags containing some parts are prepared in advance. However, different bags may contain the same type and number of parts.
* Teachers can only give one bag per child (some children may not give it).
* The same bag cannot be given to two or more children (on the contrary, some bags may not be given to anyone).
* The child who is given the bag must use all the parts contained in the bag for the tasks he / she creates.



Parts used for the assignment other than the parts in the bag must be purchased separately. The conditions for purchasing parts are as follows.

* Parts can only be purchased on class days and can only be used on that day.
* Up to L parts can be purchased in one lesson for each task.
* Prices are set according to the type of parts, and the price fluctuates depending on the date of purchase. However, none of them will be out of stock.



Under these conditions, you want to keep your lesson costs as low as possible. Therefore, I decided to create a program to calculate the minimum total cost of purchasing parts for all children.



input

The input consists of multiple datasets. The end of the input is indicated by three zero lines. Each dataset is given in the following format:


D K L
c1,1 c1,2 ... c1, K
c2,1 c2,2 ... c2, K
::
cD, 1 cD, 2 ... cD, K
M N P
r1,1 r1,2 ... r1, K
r2,1 r2,2 ... r2, K
::
rM, 1 rM, 2 ... rM, K
t1,1 t1,2 ... t1, K
t2,1 t2,2 ... t2, K
::
tP, 1 tP, 2 ... tP, K


The numbers given on each line are separated by a single space.

D (1 ≤ D ≤ 8) indicates the number of lessons, K (1 ≤ K ≤ 8) indicates the number of parts types, and L (1 ≤ L ≤ 8) indicates the number of parts that can be purchased per day. .. cd, k (1 ≤ cd, k ≤ 100) indicates the price of part k on day d.

M (1 ≤ M ≤ 200) indicates the number of task types, N (1 ≤ N ≤ M) indicates the number of students, and P (1 ≤ P ≤ 200) indicates the number of bags.

rm, k (0 ≤ rm, k ≤ 2) indicates the number of parts k required for task m, and tp, k (0 ≤ tp, k ≤ 2) indicates the number of parts k contained in the bag p.

Tasks that do not require any parts or empty bags shall not be given.

The number of datasets does not exceed 20.

output

For each data set, output the minimum value of the total parts purchase cost for all students on one line. If N kinds of works cannot be completed, -1 is output.

Example

Input

2 2 1
5 3
2 2
3 3 1
2 0
1 2
2 2
1 1
2 2 1
5 3
2 2
3 2 1
2 0
1 2
2 2
1 1
2 2 2
5 3
2 2
3 2 1
2 0
1 2
2 2
1 1
4 3 1
2 2 1
3 2 2
2 3 3
1 2 2
5 4 3
1 1 0
1 0 1
1 0 2
1 1 2
2 2 2
1 0 1
2 0 2
1 1 1
0 0 0


Output

-1
9
6
7

Solution (in CPP):

Solution:
#include <cstdio>
#include <queue>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int INF = 1 << 29;
int shift[10];

struct Edge {
    int to, cap, cost, rev;
    Edge(int t, int c, int r) : to(t), cap(c), rev(r) {}
    Edge(int t, int ca, int co, int r) : to(t), cap(ca), cost(co), rev(r) {}
};

using Graph = vector< vector< Edge > >;
struct Flow {
    vector< vector<Edge> > G;
    const int MAXC = 1 << 29;
    int n;
    vector<bool> used;
    vector<int> prevv, preve, dist;
    Flow(int n_) : G(n_), n(n_), used(n_, false), prevv(n_), preve(n_), dist(n_, MAXC) {}

    void add_edge(int from, int to, int cap, int cost) {
        G[from].push_back(Edge(to, cap, cost, G[to].size()));
        G[to  ].push_back(Edge(from, 0, -cost, G[from].size() - 1));
    }

    int dfs(int v, int t, int f) {
        if(v == t) return f;
        used[v] = true;
    }


    // ベルマンフォード法で最小費用流を解く
    // 負辺や負閉路があるときは基本的にこちらのほうが確実
    int mincost_flow(int s, int t, int f) {
        int res = 0;
        int ma = MAXC;
        while(f > 0) {
            fill(dist.begin(), dist.end(), ma);
            dist[s] = 0;
            bool update = true;
            while(update) {
                update = false;
                for(int v = 0; v < n; v++) {
                    if(dist[v] == ma) continue;
                    for(int i=0; i<G[v].size(); i++) {
                        Edge &e = G[v][i];
                        if(e.cap>0 && dist[e.to] > dist[v] + e.cost) {
                            dist[e.to] = dist[v] + e.cost;
                            prevv[e.to] = v;
                            preve[e.to] = i;
                            update = true;
                        }
                    }
                }
            }

            if(dist[t] == ma) return -1;
            int d = f;
            for(int v = t; v != s; v = prevv[v]) {
                d = min(d, G[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d * dist[t];
            for(int v = t; v != s; v = prevv[v]) {
                Edge &e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }    
    
    int fast_mincost_flow(int s, int t, int f) {
        int res = 0, ma = MAXC;
        vector<int> pot(n);
        while(f > 0) {
            using PT = pair<int, int>;
            priority_queue< PT, vector<PT>, greater<PT> > que;
            fill(dist.begin(), dist.end(), ma);

            dist[s] = 0;
            que.push(make_pair(0, s));
            while(que.size()) {
                PT cur = que.top(); que.pop();
                int v = cur.second;
                if(dist[v] < cur.first) continue;
                for(size_t i=0; i<G[v].size(); i++) {
                    Edge &e = G[v][i];
                    if(e.cap > 0 and dist[e.to] > dist[v] + e.cost + pot[v] - pot[e.to]) {
                        dist[e.to] = dist[v] + e.cost + pot[v] - pot[e.to];
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        que.push(make_pair(dist[e.to], e.to));
                    }
                }
            }
            if(dist[t] == ma) {
                return -1;
            }
            for(int v=0; v<n; v++) pot[v] += dist[v];

            int d = f;
            for(int v=t; v!=s; v=prevv[v]) {
                d = min(d, G[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d * pot[t];
            for(int v=t; v!=s; v=prevv[v]) {
                Edge &e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

void chmin(int &A, int B) {
    A = min(A, B);
}

int D, K, L, M, N, P;
int c[10][10], r[210][10], t[210][10];

int encode(vector<int> cnt) {
    int sz = cnt.size(), res = 0;
    for(int i=sz-1; i>=0; i--) {
        res = res * 3 + cnt[i];
    }
    return res;
}

int get_digit(int val, int k) {
    val /= shift[k];
    return val % 3;
}

int update_digit(int bit, int k, int val) {
    bit -= get_digit(bit, k) * shift[k];
    bit += val * shift[k];
    return bit;
}

vector<int> solve_dp(int day, const vector<int> &vec) {
    int lim = shift[K];
    vector< vector< vector<int> > > dp(K+1, vector< vector<int> >(L+1, vector<int>(lim, INF)));
    dp[0][0] = vec;

    for(int i=0; i<K; i++) {
        for(int j=0; j<=L; j++) {
            for(int bit=0; bit<lim; bit++) {
                int v = get_digit(bit, i);
                for(int x=0; x+v<=2 and x+j<=L; x++) {
                    int nbit = update_digit(bit, i, x+v);
                    int cost = c[day][i] * x;
                    chmin(dp[i+1][j+x][nbit], dp[i][j][bit] + cost);
                }
            }
        }
    }

    vector<int> res = vec;
    for(int bit=0; bit<lim; bit++) {
        for(int i=0; i<=L; i++) res[bit] = min(res[bit], dp[K][i][bit]);
    }
    return res;
}

int solve_testcase() {
    cin >> D >> K >> L;
    if(D == 0 and K == 0 and L == 0) return 1;
    for(int i=0; i<D; i++) {
        for(int j=0; j<K; j++) {
            cin >> c[i][j];
        }
    }

    // solve (DP);
    vector<int> vec(shift[K], INF);
    vec[0] = 0;
    for(int i=0; i<D; i++) {
        vec = solve_dp(i, vec);
    }

    /*
      for(int i=0; i<shift[K]; i++) {
      fprintf(stderr, "vec[%d] = %d\n", i, vec[i]);
      }
    */

    cin >> M >> N >> P;
    for(int i=0; i<M; i++) {
        for(int j=0; j<K; j++) {
            cin >> r[i][j];
        }
    }

    for(int i=0; i<P; i++) {
        for(int j=0; j<K; j++) {
            cin >> t[i][j];
        }
    }
  
    Flow fl(M + P + 2);
    int source = M + P, sink = source + 1;
    for(int i=0; i<P; i++) fl.add_edge(source, i, 1, 0);
    for(int i=0; i<M; i++) fl.add_edge(P+i, sink, 1, 0);

    // fprintf(stderr, "source sink end\n");
    vector<int> cnt(K);
    for(int i=0; i<P; i++) {
        for(int j=0; j<M; j++) {
            fill(cnt.begin(), cnt.end(), 0);

            // fprintf(stderr, "cnt = %zu\n", cnt.size());
            // fprintf(stderr, "fill end\n");
            for(int k=0; k<K; k++) cnt[k] += r[j][k];
            for(int k=0; k<K; k++) cnt[k] -= t[i][k];

            bool ok = true;
            for(int k=0; k<K; k++) ok &= (cnt[k] >= 0);
            if(!ok) continue;

            // fprintf(stderr, "before encode\n");
            int bit = encode(cnt);
            // fprintf(stderr, "bit = %d, size = %zu\n", bit, vec.size());
            if(vec[bit] == INF) continue;
            // fprintf(stderr, "add edge: [%d, %d, %d]\n", i, j, vec[bit]);
            fl.add_edge(i, P+j, 1, vec[bit]);
        }
    }

    for(int i=0; i<M; i++) {
        fill(cnt.begin(), cnt.end(), 0);
        for(int k=0; k<K; k++) cnt[k] += r[i][k];
        int bit = encode(cnt);
        if(vec[bit] == INF) continue;
        // fprintf(stderr, "# add edge: [source, %d, %d]\n", i, vec[bit]);
        fl.add_edge(source, P+i, 1, vec[bit]);
    }

    // fprintf(stderr, "before flow\n");
    int ans = fl.fast_mincost_flow(source, sink, N);
    cout << ans << endl;
    return 0;
}

int main() {
    shift[0] = 1;
    for(int i=1; i<10; i++) shift[i] = shift[i-1] * 3;
  
    while(!solve_testcase());
}