#include <bits/stdc++.h>
using namespace std;
int n, A, B;
vector<int> s;
vector<vector<bool> > adj, g, f;
int cnt;
vector<int> post;
vector<bool> vis;
vector<vector<int> > scc;
vector<int> prz;
vector<int> nwd;
vector<vector<bool> > ad;
vector<int> sum;
vector<pair<int, int> > wid;
void read() {
  scanf("%d %d %d", &n, &A, &B);
  adj.resize(n);
  char c[5001];
  for (int i = 0; i < (n); ++i) {
    scanf("%s", c);
    string ss(c);
    adj[i].resize(n, 0);
    for (int j = 0; j < (n); ++j) {
      adj[i][j] = (ss[j] == '1');
    }
  }
  s.resize(n);
  g.resize(n);
  wid.resize(n);
  char cc[2000001];
  for (int i = 0; i < (n); ++i) {
    wid[i].first = 0;
    scanf("%d", &s[i]);
    scanf("%s", cc);
    string ss(cc);
    g[i].resize(s[i], 0);
    for (int j = 0; j < (s[i]); ++j) {
      g[i][j] = (ss[j] == '1');
      wid[i].first += g[i][j];
    }
  }
}
void write() {}
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < (n); ++i)
    if (!vis[i] && adj[u][i]) dfs(i);
  post.push_back(u);
}
void dfsutil(int u) {
  vis[u] = 1;
  scc[cnt].push_back(u);
  prz[u] = cnt;
  for (int i = 0; i < (n); ++i)
    if (!vis[i] && adj[i][u]) dfsutil(i);
}
void scc_topsort() {
  prz.resize(n);
  vis.resize(n, 0);
  for (int i = 0; i < (n); ++i)
    if (!vis[i]) dfs(i);
  vis.clear();
  vis.resize(n, 0);
  for (int i = (n - 1); i >= (0); --i)
    if (!vis[post[i]]) {
      vector<int> new_scc;
      scc.push_back(new_scc);
      dfsutil(post[i]);
      ++cnt;
    }
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void propagate(int a, int b) {
  int gc = gcd(nwd[a], nwd[b]);
  vector<bool> nw(gc, 0);
  for (int i = 0; i < (nwd[a]); ++i)
    if (f[a][i]) nw[i % gc] = 1;
  for (int i = 0; i < (gc); ++i)
    if (nw[i])
      for (int j = 0; j < (nwd[b] / gc); ++j) f[b][j * gc + i] = 1;
}
void gcds() {
  nwd.resize(cnt);
  for (int i = 0; i < (cnt); ++i) {
    nwd[i] = s[scc[i][0]];
    for (int j = (1); j <= (scc[i].size() - 1); ++j)
      nwd[i] = gcd(nwd[i], s[scc[i][j]]);
  }
  f.resize(cnt);
  for (int i = 0; i < (cnt); ++i) {
    f[i].resize(nwd[i], 0);
    for (int j = 0; j < (scc[i].size()); ++j) {
      int v = scc[i][j];
      for (int k = 0; k < (s[v]); ++k)
        if (g[v][k]) f[i][k % nwd[i]] = 1;
    }
  }
  for (int i = (0); i <= (cnt - 2); ++i) propagate(i, i + 1);
}
vector<int> tt0, tt1, counter1, counter2;
const long long maxval = 2e6;
const long long mod = 1e9 + 7;
vector<vector<long long> > binnom;
void pascal() {
  binnom.resize(n + 1);
  for (int i = 0; i < (n + 1); ++i) binnom[i].resize(n + 1, 0);
  binnom[0][0] = 1;
  for (int i = (1); i <= (n); ++i) {
    binnom[i][0] = 1;
    binnom[i][i] = 1;
    for (int j = (1); j <= (i - 1); ++j) {
      binnom[i][j] = (binnom[i - 1][j - 1] + binnom[i - 1][j]) % mod;
    }
  }
}
vector<int> counter0;
void tops() {
  for (int i = 0; i < (n); ++i) {
    wid[i].second = 0;
    for (int j = 0; j < (nwd[prz[i]]); ++j) wid[i].second += f[prz[i]][j];
    wid[i].second *= (s[i] / nwd[prz[i]]);
  }
  pascal();
}
void final_answer() {
  long long res = 0;
  counter0.resize(maxval + 2, 0);
  counter1.resize(maxval + 2, 0);
  for (int i = 0; i < (n); ++i) {
    counter0[wid[i].second]++;
    counter1[wid[i].first]++;
    counter1[wid[i].second]--;
  }
  int curr_cnt = 0;
  for (int i = (0); i <= (maxval); ++i) {
    curr_cnt += counter1[i];
    counter1[i] = curr_cnt;
  }
  counter2.resize(maxval + 2, 0);
  cnt = 0;
  sort(wid.begin(), wid.end());
  for (int i = (n - 1); i >= (0); --i) {
    cnt++;
    if (wid[i].first == 0) break;
    counter2[wid[i].first - 1] = cnt;
  }
  for (int i = (maxval); i >= (0); --i)
    if (counter2[i] < counter2[i + 1]) counter2[i] = counter2[i + 1];
  for (int i = (0); i <= (maxval); ++i) {
    if (counter2[i] >= A) continue;
    int dif = A - counter2[i];
    for (int j = (1); j <= (min(B, min(dif, counter0[i]))); ++j) {
      long long sadd = 0;
      for (int k = max(0, B - j - counter2[i]); k <= min(counter1[i], B - j);
           ++k)
        if (j + k + counter2[i] <= A) {
          sadd =
              (sadd + binnom[counter1[i]][k] * binnom[counter2[i]][B - j - k]) %
              mod;
        }
      long long add = sadd * binnom[counter0[i]][j];
      res = (res + add) % mod;
    }
  }
  printf("%Ld\n", res);
}
int main() {
  read();
  scc_topsort();
  gcds();
  tops();
  final_answer();
  return 0;
}
