In Isart people don't die. There are n gangs of criminals. The i-th gang contains si evil people numerated from 0 to si - 1. Some of these people took part in a big mine robbery and picked one gold bullion each (these people are given in the input). That happened 10100 years ago and then all of the gangs escaped to a remote area, far from towns.

During the years, they were copying some gold bullions according to an organized plan in order to not get arrested. They constructed a tournament directed graph (a graph where there is exactly one directed edge between every pair of vertices) of gangs (the graph is given in the input). In this graph an edge from u to v means that in the i-th hour the person <image> of the gang u can send a fake gold bullion to person <image> of gang v. He sends it if he has some bullion (real or fake), while the receiver doesn't have any. Thus, at any moment each of the gangsters has zero or one gold bullion. Some of them have real bullions, and some of them have fake ones.

In the beginning of this year, the police has finally found the gangs, but they couldn't catch them, as usual. The police decided to open a jewelry store so that the gangsters would sell the bullions. Thus, every gangster that has a bullion (fake or real) will try to sell it. If he has a real gold bullion, he sells it without problems, but if he has a fake one, there is a choice of two events that can happen: 

  * The person sells the gold bullion successfully. 
  * The person is arrested by police. 



The power of a gang is the number of people in it that successfully sold their bullion. After all selling is done, the police arrests b gangs out of top gangs. Sort the gangs by powers, we call the first a gang top gangs(you can sort the equal powers in each order). Consider all possible results of selling fake gold bullions and all possible choice of b gangs among the top gangs. Count the number of different sets of these b gangs modulo 109 + 7. Two sets X and Y are considered different if some gang is in X and isn't in Y.

Input

The first line contains four integers n, a and b (1 ≤ b ≤ a ≤ n ≤ 5·103) — the number of gangs, the constants a and b from the statement.

Then n lines follow, each line contains a string of size n consisting of zeros and ones. The j-th character in the i-th of these lines is equal to 1, then the vertex i have a directed edge to the vertex j. It is guaranteed that aii = 0 and aij + aji = 1 if i ≠ j.

Then n lines follow, each line starts with the integer si (1 ≤ si ≤ 2·106) — the number of gangsters in the i-th gang, and then contains a string of zeros and ones with length si. The j-th character is 0 if the j-th person of the i-th gang had a real gold bullion initially, otherwise it is 1. It is guaranteed that the sum of si does not exceed 2·106.

Output

Print single integer: the number of different sets of b gangs the police can arrest modulo 109 + 7.

Examples

Input

2 2 1
01
00
5 11000
6 100000


Output

2


Input

5 2 1
00000
10000
11011
11000
11010
2 00
1 1
6 100110
1 0
1 0


Output

5
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, MAXM = 2e6 + 5;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
vector<int> G[5005];
vector<int> have_real[5005], have_gold[5005];
int n, a, b, siz[5005], all_gold[5005], L[5005], R[5005];
int siz_new[5005], pos[5005], dfn[5005], low[5005], have_last[5005], times, tot;
int in[5005];
int inv[2000005], fac[2000005];
stack<int> s;
int qpow(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = 1ll * ret * a % MOD;
    b >>= 1;
    a = 1ll * a * a % MOD;
  }
  return ret;
}
void Tarjan(int u) {
  low[u] = dfn[u] = ++times;
  s.push(u);
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!dfn[v]) {
      Tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (!pos[v])
      low[u] = min(low[u], low[v]);
  }
  if (dfn[u] == low[u]) {
    int t = -1;
    tot++;
    while (t != u) {
      t = s.top();
      s.pop();
      pos[t] = tot;
      siz_new[tot] = gcd(siz[t], siz_new[tot]);
    }
  }
}
int C(int x, int y) {
  if (x < y || x < 0 || y < 0) return 0;
  return 1ll * (1ll * fac[x] * inv[y] % MOD) * inv[x - y] % MOD;
}
inline void init(int nn) {
  fac[0] = 1;
  for (int i = 1; i <= nn; i++) fac[i] = 1ll * fac[i - 1] * i % MOD;
  inv[nn] = qpow(fac[nn], MOD - 2);
  for (int i = nn; i; i--) inv[i - 1] = 1ll * inv[i] * i % MOD;
}
int main() {
  init(MAXM - 5);
  int x, ans = 0;
  scanf("%d %d %d", &n, &a, &b);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      scanf("%1d", &x);
      if (x) G[i].push_back(j);
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &siz[i]);
    for (int j = 1; j <= siz[i]; j++) {
      scanf("%1d", &x);
      L[i] += x;
      have_real[i].push_back(x);
    }
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) Tarjan(i);
  for (int i = 1; i <= tot; i++) have_gold[i].resize(siz_new[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < siz[i]; j++)
      have_gold[pos[i]][j % siz_new[pos[i]]] |= have_real[i][j];
  }
  for (int i = tot; i >= 2; i--) {
    int g = gcd(siz_new[i], siz_new[i - 1]);
    for (int j = 0; j < siz_new[i]; j++) {
      have_gold[i - 1][j % g] |= have_gold[i][j];
      all_gold[i] += have_gold[i][j];
    }
  }
  for (int i = 0; i < siz_new[1]; i++) all_gold[1] += have_gold[1][i];
  for (int i = 1; i <= n; i++)
    R[i] = 1ll * all_gold[pos[i]] * siz[i] / siz_new[pos[i]];
  for (int i = 1; i <= n; i++) {
    int cnt1 = 0, cnt2 = 0;
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (L[j] > R[i])
        cnt1++;
      else if (R[i] < R[j] || (R[i] == R[j] && j < i))
        cnt2++;
    }
    if (cnt1 > a - 1) continue;
    for (int j = min(b, min(cnt2, a - 1 - cnt1)); j + cnt1 + 1 >= b; j--) {
      ans += 1ll * C(cnt2, j) * C(cnt1, b - j - 1) % MOD;
      if (ans > MOD) ans -= MOD;
      if (ans < 0) ans += MOD;
    }
  }
  printf("%d\n", ans);
  return 0;
}
