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<bits/stdc++.h>

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define INIT(a) memset(a,0,sizeof(a))
#define pb push_back
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

struct edge{
  ll from,to,cost,cap,rev;
};

const ll INF = 1LL<<50;
const ll INF2 = 1LL<<60;
const ll V = 1000;
vector<edge> G[V];

void AddEdge(ll s,ll g,ll c,ll p){
  G[s].pb((edge){s,g,c,p,(ll)G[g].sz});
  G[g].pb((edge){g,s,-c,0,(ll)G[s].sz-1});
}

ll d[V];
ll h[V],pv[V],pe[V];
ll v;
bool use[V];

ll MinCostFlow(ll s,ll t,ll f){
  ll res = 0;
  fill(h,h+v,0);
  while(f>0){
    fill(d,d+v,INF2);
    memset(use,0,sizeof(use));
    d[s] = 0;

    while(true){
      int u = -1;
      rep(i,v){
	if(!use[i] && (u<0 || d[u] > d[i]))u = i;
      } 

      if(u<0 || d[u] == INF2)break;
      use[u] = true;

      rep(i,G[u].sz){
	edge &e = G[u][i];
	if(e.cap>0 && d[e.to] > d[u] + e.cost + h[u] - h[e.to]){
	  d[e.to] = d[u] + e.cost + h[u] - h[e.to];
	  pv[e.to] = u; pe[e.to] = i;
	}
      }	  
    }

    if(d[t]==INF2)return -1;
    rep(u,v)h[u] += d[u];

    ll x = f;
    for(int u=t;u!=s;u=pv[u])x = min(x,G[pv[u]][pe[u]].cap);
    f -= x;
    res += x*h[t];
    for(int u=t;u!=s;u=pv[u]){
      edge &e = G[pv[u]][pe[u]];
      e.cap -= x; G[u][e.rev].cap += x;
    }
  }
  return res;
}


ll dp[10][1<<16][10];

int main(){
  ll d,k,l;
  ll c[10][10];
  ll n,m,p;
  ll r[220][10], t[220][10];

  while(scanf("%lld%lld%lld",&d,&k,&l),d){
    rep(i,d)rep(j,k)scanf("%lld",&c[i][j]);
    scanf("%lld%lld%lld",&m,&n,&p);
    rep(i,m)rep(j,k)scanf("%lld",&r[i][j]);
    rep(i,p)rep(j,k)scanf("%lld",&t[i][j]);

    rep(i,d+1)rep(j,1<<(2*k))rep(x,l+1)dp[i][j][x] = INF;
    dp[0][0][0] = 0;

    rep(i,d)rep(j,1<<(2*k))rep(x,l+1){
      if(dp[i][j][x]==INF)continue;
      dp[i+1][j][0] = min(dp[i+1][j][0], dp[i][j][x]);
      
      if(x==l)continue;
      rep(y,k){
	if( ((j>>(2*y))&3) >= 2 )continue;
	ll& nxt2 = dp[i][j+(1<<(2*y))][x+1];
	nxt2 = min(nxt2, dp[i][j][x] + c[i][y]);
      }
    }

    v = p+m+3;
    rep(i,v)G[i].clear();

    rep(i,p)rep(j,m){
      int dif[10];
      rep(x,k)dif[x] = r[j][x] - t[i][x];
      if(*min_element(dif,dif+k)<0)continue;
      int need = 0;
      rep(x,k)need |= dif[x] << (2*x);
      if(dp[d][need][0] == INF)continue;
      AddEdge(i,p+1+j,dp[d][need][0],1);
    }
    rep(j,m){
      int need = 0;
      rep(x,k)need |= r[j][x] << (2*x);
      if(dp[d][need][0] == INF)continue;
      AddEdge(p,p+1+j,dp[d][need][0],1);
    }

    rep(i,p)AddEdge(v-2,i,0,1);
    AddEdge(v-2,p,0,INF);
    rep(j,m)AddEdge(p+1+j,v-1,0,1);

    cout << MinCostFlow(v-2,v-1,n) << endl;
  }
}