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 <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <functional>
#include <queue>
using namespace std;
const int MAX_V = 100010;
typedef int Capacity;
typedef int Cost;
const int inf = 1 << 28;

struct Edge {
	int dst;
	Capacity cap, cap_orig;
	Cost cost;
	int revEdge; bool isRev;
	Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
		:dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(revEdge), isRev(isRev) {
	}
};


struct PrimalDual {
	int n;
	vector<vector<Edge> > g;
	vector<int> top;
	PrimalDual(int n_) : n(n_), g(vector<vector<Edge> >(n_)) {}
	void add_edge(int src, int dst, Capacity cap, Cost cost) { // ?????????
		g[src].push_back(Edge{ dst, cap, cost, (int)g[dst].size(), false });
		g[dst].push_back(Edge{ src, 0, -cost, (int)g[src].size() - 1, true });
	}
	Cost solve(int s, int t, int f) {
		Cost res = 0;
		static Cost h[MAX_V], dist[MAX_V];
		static int prevv[MAX_V], preve[MAX_V];

		fill(h, h + n, 0);
		if(top.size()) {
			assert(top.size() == n);
			for(int i = 0; i < n; i++) {
				int v = top[i];
				for(int i = 0; i < g[v].size(); i++) {
					Edge& e = g[v][i];
					if(e.cap == 0) continue;
					int u = e.dst;
					h[u] = min(h[u], h[v] + e.cost);
				}
			}
		}

		while(f > 0) {
			typedef pair<Cost, int> pcv;
			priority_queue<pcv, vector<pcv>, greater<pcv> > q;
			for(int i = 0; i < n; i++) {
				dist[i] = inf;
			}
			dist[s] = 0;
			q.push(pcv(0, s));
			while(q.size()) {
				pcv p = q.top(); q.pop();
				int v = p.second;
				if(dist[v] < p.first) continue;
				for(int i = 0; i < g[v].size(); i++) {
					Edge &e = g[v][i];
					if(e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
						dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
						prevv[e.dst] = v;
						preve[e.dst] = i;
						q.push(pcv(dist[e.dst], e.dst));
					}
				}
			}
			if(dist[t] == inf) {
				return -1;
			}
			for(int v = 0; v < n; v++) {
				h[v] += dist[v];
			}
			// s-t ????????????????????£??????????????????
			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 * h[t];
			for(int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.revEdge].cap += d;
			}
		}
		return res;
	}
	// ??????????????????=???????????????-?????¨??????????????¨???
	void view() {
		for(int i = 0; i < g.size(); i++) {
			for(int j = 0; j < g[i].size(); j++) {
				if(!g[i][j].isRev) {
					Edge& e = g[i][j];
					printf("%3d->%3d (flow:%d)\n", i, e.dst, e.cap_orig - e.cap);
				}
			}
		}
	}
};



const int INF = 1 << 28;
int cost[8][8];
int req[200][8];
int bag[200][8];
int dp[9][6562][9];
int sum[6562];

vector<int> f(int n) {
	vector<int> ret(8);
	for(int i = 0; i < 8; i++) {
		ret[i] = n % 3;
		n /= 3;
	}
	return ret;
}

int g(vector<int> n) {
	int ret = 0;
	for(int i = 7; i >= 0; i--) {
		ret = ret * 3 + n[i];
	}
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int D, K, L, M, N, P;
	while(cin >> D >> K >> L, D | K | L) {
		for(int i = 0; i < D; i++) {
			for(int j = 0; j < K; j++) {
				cin >> cost[i][j];
			}
		}
		cin >> M >> N >> P;
		for(int i = 0; i < M; i++) {
			for(int j = 0; j < K; j++) {
				cin >> req[i][j];
			}
		}
		for(int i = 0; i < P; i++) {
			for(int j = 0; j < K; j++) {
				cin >> bag[i][j];
			}
		}

		fill((int*)begin(dp), (int*)end(dp), INF);
		dp[0][0][0] = 0;
		for(int i = 0; i < D; i++) {// ?????\???
			if(i != 0) {
				for(int j = 0; j < 6561; j++) {// ??¶???
					for(int k = 0; k <= L; k++) {
						dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][k]);
					}
				}
			}
			for(int j = 0; j < 6561; j++) {// ??¶???
				vector<int> s = f(j);
				for(int k = 0; k <= L; k++) { // ???????????£???
					if(dp[i][j][k] == INF) continue;
					for(int l = 0; l < K; l++) { // ????????¨???
						for(int m = 1; k + m <= L; m++) {// ????????????
							if(s[l] + m > 2) continue;
							s[l] += m;
							int nj = g(s);
							dp[i][nj][k + m] = min(dp[i][nj][k + m], dp[i][j][k] + cost[i][l] * m);
							s[l] -= m;
						}
					}
				}
			}
		}

		fill((int*)begin(sum), (int*)end(sum), INF);
		for(int i = 0; i < D; i++) {
			for(int j = 0; j < 6561; j++) {
				for(int k = 0; k <= L; k++) {
					sum[j] = min(sum[j], dp[i][j][k]);
				}
			}
		}

		PrimalDual pd(M + P + 1 + 2);
		int S = M + P + 1, T = S + 1;
		for(int m = 0; m < M; m++) {
			for(int p = 0; p < P; p++) {
				bool flag = true;
				vector<int> s(8);
				for(int k = 0; k < K; k++) {
					s[k] = req[m][k] - bag[p][k];
					if(s[k] < 0) {
						flag = false;
						break;
					}
				}
				if(flag) {
					int c = sum[g(s)];
					pd.add_edge(m, M + p, 1, c);
				}
			}
			vector<int> s(8);
			for(int k = 0; k < K; k++) {
				s[k] = req[m][k];
			}
			if(sum[g(s)] != INF) {
				pd.add_edge(m, M + P, 1000000, sum[g(s)]);
			}
			pd.add_edge(S, m, 1, 0);
		}
		for(int p = 0; p < P; p++) {
			pd.add_edge(M + p, T, 1, 0);
		}
		pd.add_edge(M + P, T, 1000000, 0);
		cout << pd.solve(S, T, N) << endl;
	}
}