#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, MAXL = 200 + 5, MAXN = 200 + 5, MAXM = 20,
          MAXSIZE = 200 + 5, MAXK = 500 + 5;
int N, M, K;
int num1[MAXL], len1;
int num2[MAXL], len2;
int len, num[MAXL];
int value[MAXN];
int tot, g[MAXSIZE][MAXM], v[MAXSIZE], q[MAXSIZE], fail[MAXSIZE];
int f[MAXSIZE][MAXK], tmp[MAXSIZE][MAXK];
void add(int len, int vvvv) {
  int now = 0;
  for (int i = 1; i <= len; ++i) {
    if (!g[now][num[i]]) g[now][num[i]] = ++tot;
    now = g[now][num[i]];
  }
  v[now] += vvvv;
}
int isok() {
  int now = 0;
  int res = 0;
  for (int i = 1; i <= len; ++i) {
    now = g[now][num[i]];
    res += v[now];
  }
  if (res <= K)
    return 1;
  else
    return 0;
}
int doit() {
  for (int j = 0; j <= tot; ++j)
    for (int k = 0; k <= K + 1; ++k) f[j][k] = 0;
  for (int x = 0; x <= tot; ++x) f[x][v[x]]++;
  int res = 0;
  for (int i = len; i; --i) {
    int now = 0;
    int vv = 0;
    for (int j = 1; j <= i - 1; ++j) {
      now = g[now][num[j]];
      vv += v[now];
    }
    if (i != 1) {
      int lll = 1;
      if (len == i) lll = 0;
      for (int j = lll; j < M; ++j) {
        for (int k = 0; k <= K; ++k) res = (res + f[g[0][j]][k]) % MOD;
      }
    }
    if (vv <= K) {
      int limit = 0;
      if (i == 1 && i != len) limit = 1;
      for (int x = limit; x < num[i]; ++x) {
        int tn = g[now][x];
        for (int k = 0; k <= K - vv; ++k) {
          res = (res + f[tn][k]) % MOD;
        }
      }
    }
    for (int x = 0; x <= tot; ++x) {
      for (int k = 0; k <= K + 1; ++k) tmp[x][k] = 0;
      for (int y = 0; y < M; ++y) {
        int tn = g[x][y];
        for (int k = 0; k <= K - v[x]; ++k)
          tmp[x][k + v[x]] = (tmp[x][k + v[x]] + f[tn][k]) % MOD;
      }
    }
    for (int x = 0; x <= tot; ++x)
      for (int k = 0; k <= K; ++k) f[x][k] = tmp[x][k];
  }
  return res;
}
int main() {
  scanf("%d%d%d", &N, &M, &K);
  scanf("%d", &len1);
  for (int i = 1; i <= len1; ++i) scanf("%d", &num1[i]);
  scanf("%d", &len2);
  for (int i = 1; i <= len2; ++i) scanf("%d", &num2[i]);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &len);
    for (int j = 1; j <= len; ++j) scanf("%d", &num[j]);
    scanf("%d", &value[i]);
    add(len, value[i]);
  }
  int head = 0, tail = 0;
  for (int i = 0; i < M; ++i)
    if (g[0][i]) {
      q[++tail] = g[0][i];
      fail[g[0][i]] = 0;
    }
  while (head != tail) {
    int x = q[++head];
    for (int i = 0; i < M; ++i)
      if (!g[x][i])
        g[x][i] = g[fail[x]][i];
      else {
        fail[g[x][i]] = g[fail[x]][i];
        v[g[x][i]] += v[fail[g[x][i]]];
        q[++tail] = g[x][i];
      }
  }
  len = len2;
  for (int i = 1; i <= len; ++i) num[i] = num2[i];
  int rr = doit();
  len = len1;
  for (int i = 1; i <= len; ++i) num[i] = num1[i];
  int ll = doit();
  len = len2;
  for (int i = 1; i <= len; ++i) num[i] = num2[i];
  cout << ((rr - ll + isok()) % MOD + MOD) % MOD << endl;
  return 0;
}
