#include <bits/stdc++.h>
using namespace std;
const int mm = 1000000007;
struct acanode {
  int g[31], f, h, v;
  void cle() {
    memset(g, 0, sizeof(g));
    h = 0;
  }
} t[301];
int i, j, k, n, m, lim, l[301], r[301], f[301][301][601], w[301], g[301][31],
    c[301], tot, e[90001][2], cot, ans, q[301], ts[301], now;
void ins(int x) {
  int i, p = 1;
  for (i = 1; i <= w[0]; i++) {
    if (!t[p].g[w[i]]) {
      t[p].g[w[i]] = ++tot;
      t[tot].cle();
    }
    p = t[p].g[w[i]];
  }
  e[++cot][0] = x;
  e[cot][1] = t[p].h;
  t[p].h = cot;
}
void build() {
  int i, j, k, l, r, tmp;
  for (l = r = i = t[1].v = 0; i < m; i++)
    if (!t[1].g[i])
      t[1].g[i] = 1;
    else
      q[++r] = t[1].g[i], t[t[1].g[i]].f = 1;
  memset(ts, 0, sizeof(ts));
  now = 0;
  while (l < r) {
    j = q[++l];
    now++;
    for (i = t[j].h, t[j].v = 0; i; i = e[i][1])
      if (ts[e[i][0]] != now) ts[e[i][0]] = now, t[j].v += c[e[i][0]];
    for (i = 0; i < m; i++)
      if (t[j].g[i]) {
        q[++r] = t[j].g[i];
        for (k = t[j].f; !t[k].g[i]; k = t[k].f)
          ;
        t[t[j].g[i]].f = t[k].g[i];
        for (tmp = t[t[j].g[i]].h; tmp && e[tmp][1]; tmp = e[tmp][1])
          ;
        if (tmp)
          e[tmp][1] = t[t[k].g[i]].h;
        else
          t[t[j].g[i]].h = t[t[k].g[i]].h;
      }
  }
}
int work(int p, int x) {
  int i;
  if (g[p][x] != -1) return g[p][x];
  for (i = p; !t[i].g[x]; i = t[i].f)
    ;
  return g[p][x] = t[i].g[x];
}
int solve(int *a) {
  int res, i, j, k, l, s, tmp, t1, t2;
  memset(f, 0, sizeof(f));
  if (!a[0]) return 0;
  for (t1 = 1, i = t2 = 0; i < a[0]; i++) {
    if (t2 <= lim) {
      if (i) {
        for (j = 0; j < a[i + 1]; j++) {
          k = work(t1, j);
          tmp = t2 + t[k].v;
          if (tmp > lim) continue;
          f[i + 1][k][tmp] = (f[i + 1][k][tmp] + 1) % mm;
        }
      }
      t1 = work(t1, a[i + 1]);
      t2 += t[t1].v;
    }
    for (j = 1; j < ((i) ? m : a[1]); j++) {
      k = work(1, j);
      tmp = t[k].v;
      if (tmp > lim) continue;
      f[i + 1][k][tmp] = (f[i + 1][k][tmp] + 1) % mm;
    }
    for (j = 1; j <= tot; j++)
      for (k = 0; k <= lim; k++)
        if (f[i][j][k])
          for (l = 0; l < m; l++) {
            s = work(j, l);
            tmp = k + t[s].v;
            if (tmp > lim) continue;
            f[i + 1][s][tmp] = (f[i + 1][s][tmp] + f[i][j][k]) % mm;
          }
  }
  for (res = i = 0; i <= lim; i++)
    for (j = 1; j <= tot; j++) res = (res + f[a[0]][j][i]) % mm;
  if (t2 <= lim) res = (res + 1) % mm;
  return res;
}
int main() {
  scanf("%d%d%d", &n, &m, &lim);
  scanf("%d", &l[0]);
  for (i = 1; i <= l[0]; i++) scanf("%d", &l[i]);
  l[l[0]]--;
  for (i = l[0]; l[i] < 0; i--) l[i] += m, l[i - 1]--;
  if (!l[1]) {
    l[0]--;
    for (i = 1; i <= l[0]; i++) l[i] = l[i + 1];
  }
  scanf("%d", &r[0]);
  for (i = 1; i <= r[0]; i++) scanf("%d", &r[i]);
  tot = 1;
  cot = 0;
  t[1].cle();
  for (i = 1; i <= n; i++) {
    scanf("%d", &w[0]);
    for (j = 1; j <= w[0]; j++) scanf("%d", &w[j]);
    scanf("%d", &c[i]);
    ins(i);
  }
  build();
  memset(g, -1, sizeof(g));
  ans = ((solve(r) - solve(l)) % mm + mm) % mm;
  printf("%d\n", ans);
  return 0;
}
