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 <algorithm>
#include <cstdlib>
#include <cassert>
using namespace std;

int D, K, L;
int M, N, P;
vector<vector<int> > c, r, t;

struct edge {
	int to, cap, cost, rev;
	edge(int to_, int cap_, int cost_, int rev_) {
		to = to_; cap = cap_; cost = cost_; rev = rev_;
	};
};

int V;
vector<vector<edge> > G;
vector<int> dist;
vector<int> prevv, preve;
const int INF = 1e7;

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 min_cost_flow(int src, int snk, int f) {
	int res = 0;
	while(f > 0) {
		fill(dist.begin(), dist.end(), INF);
		dist[src] = 0;
		bool update = true;
		while(update) {
			update = false;
			for(int v = 0; v < V; v++) {
				if(dist[v] == INF) 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[snk] == INF)
			return -1;

		int d = f;
		for(int v = snk; v != src; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		assert(d==1);
		f -= d;
		res += d * dist[snk];
		for(int v = snk; v != src; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int dp[10][10000][10];
int solve_dp(int day, int items, int rest) {
	assert(items >= 0);
	if(day < 0 || items < 0 || rest < 0) return INF;
//	cout << day << "," << items << "," << rest << endl;
	if(dp[day][items][rest] + 1)
		return dp[day][items][rest];
	int cnt[8] = {};
	int tmp = items;
	for(int i = 0; i < K; i++) {
		cnt[K-1-i] = tmp % 3;
		tmp /= 3;
	}
	assert(!tmp);

	dp[day][items][rest] = INF;
	dp[day][items][rest] =
		min(dp[day][items][rest], solve_dp(day-1, items, L));
	tmp = 1;
	for(int i = 0; i < K; i++) {
		if(cnt[K-1-i]) {
			dp[day][items][rest] =
				min(dp[day][items][rest], solve_dp(day, items-tmp, rest-1) + c[day][K-1-i]);
		}
		tmp *= 3;
	}
	return dp[day][items][rest];
}

bool input() {
	cin >> D >> K >> L;
	if(D + K + L == 0) return false;
	c.clear();
	c.resize(D);
	for(int i = 0; i < D; i++) {
		c[i].resize(K);
		for(int j = 0; j < K; j++) {
			cin >> c[i][j];
		}
	}
	cin >> M >> N >> P;
	r.clear();
	r.resize(M);
	for(int i = 0; i < M; i++) {
		r[i].resize(K);
		for(int j = 0; j < K; j++) {
			cin >> r[i][j];
		}
	}
	t.clear();
	t.resize(P);
	for(int i = 0; i < P; i++) {
		t[i].resize(K);
		for(int j = 0; j < K; j++) {
			cin >> t[i][j];
		}
	}
	return true;
}

int main() {
	while(input()) {
		V = M+P+3;
		G.clear();
		dist.clear();
		prevv.clear();
		preve.clear();
		for(int i = 0; i < 10; i++)
			for(int j = 0; j < 10000; j++)
				for(int k = 0; k < 10; k++)
					dp[i][j][k] = -1;
		for(int i = 0; i <= L; i++)
			dp[0][0][i] = 0;

		// make edge
		G.resize(V);
		dist.resize(V,0);
		prevv.resize(V,0);
		preve.resize(V,0);
		for(int i = 0; i < M; i++)
			add_edge(0, 1+i, 1, 0);
		for(int i = 0; i < M; i++) {
			for(int j = 0; j < P+1; j++) {
				int item = 0;
				bool flg = true;
				for(int k = 0; k < K; k++) {
					item *= 3;
					if(j < P) {
						item += r[i][k]-t[j][k];
						if(r[i][k]-t[j][k]<0)
							flg = false;
					}
					else {
						item += r[i][k];
					}
				}
				if(flg) {
					int C = solve_dp(D-1,item,L);
					if(C < INF)
						add_edge(1+i, M+1+j, j < P ? 1 : 200, C);
				}
			}
		}
		for(int i = 0; i < P+1; i++)
			add_edge(M+1+i, M+P+2, i < P ? 1 : 200, 0);

		int ans = min_cost_flow(0,M+P+2,N);
		cout << ans << endl;
	}
}