#include <bits/stdc++.h>
using namespace std;
const int P = 1000000007;
const int N = 205;
int n, m, K, T, q[N], v[N], fail[N], c[N][25], f[2][2][N][505];
void ins() {
  int L, x = 1, y, u;
  scanf("%d", &L);
  for (int i = 0; i < L; ++i) {
    scanf("%d", &y);
    if (!c[x][y]) c[x][y] = T++;
    x = c[x][y];
  }
  scanf("%d", &u), v[x] += u;
}
void build() {
  for (int i = 0; i < m; ++i) c[0][i] = 1;
  int h = 0, t = 1;
  q[1] = 1;
  while (h < t) {
    int x = q[++h], y, z;
    for (int i = 0; i < m; ++i)
      if (y = c[x][i]) {
        z = fail[x];
        while (z && !c[z][i]) z = fail[z];
        z = c[z][i], fail[y] = z, v[y] += v[z], q[++t] = y;
      } else
        c[x][i] = c[fail[x]][i];
  }
}
void upd(int &y, int x) {
  y += x;
  if (y >= P) y -= P;
}
struct num {
  int L, a[N];
  void read() {
    scanf("%d", &L);
    for (int i = 0; i < L; ++i) scanf("%d", a + i);
  }
  int calc(bool flag) {
    int ans = 0, x = 1, y = 0;
    for (int i = 0; i < L; ++i) x = c[x][a[i]], y += v[x];
    if (flag && y < K) ans = 1;
    memset(f, 0, sizeof(f));
    f[0][0][1][0] = 1;
    for (int i = 0; i < L; ++i) {
      int p = i & 1, q = p ^ 1, z;
      if (i)
        for (int j = 0; j < m; ++j)
          if (j) upd(f[q][1][c[1][j]][v[c[1][j]]], 1);
      for (int b = 0; b < 2; ++b)
        for (int x = 0; x < T; ++x)
          for (int k = 0; k < K; ++k)
            if (z = f[p][b][x][k]) {
              f[p][b][x][k] = 0;
              for (int j = 0; j < m; ++j)
                if ((i || j) && (b || j <= a[i]))
                  if (k + v[c[x][j]] < K)
                    upd(f[q][b || j < a[i]][c[x][j]][k + v[c[x][j]]], z);
            }
    }
    int p = L & 1;
    for (int x = 0; x < T; ++x)
      for (int k = 0; k < K; ++k) upd(ans, f[p][1][x][k]);
    return (ans % P + P) % P;
  }
} L, R;
int main() {
  scanf("%d%d%d", &n, &m, &K), ++K;
  L.read(), R.read();
  T = 2;
  for (int i = 0; i < n; ++i) ins();
  build();
  printf("%d\n", (R.calc(1) - L.calc(0) + P) % P);
  return 0;
}
