#include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
const long long MOD = (long long)1e9 + 7;
int n, m, k, cnt;
int nxt[210][22], val[210], fail[210];
int l[210], r[210], lenL, lenR;
int NewTrie() {
  int tmp = cnt++;
  val[tmp] = 0;
  for (int i = 0; i < m; i++) nxt[tmp][i] = -1;
  return tmp;
}
void Insert(int tmp, int len) {
  int x;
  for (int i = 0; i < len; i++) {
    scanf("%d", &x);
    if (nxt[tmp][x] == -1) nxt[tmp][x] = NewTrie();
    tmp = nxt[tmp][x];
  }
  scanf("%d", &x);
  val[tmp] += x;
}
queue<int> q;
void Build(int root) {
  fail[root] = root;
  for (int i = 0; i < m; i++) {
    if (nxt[root][i] == -1) {
      nxt[root][i] = root;
    } else {
      fail[nxt[root][i]] = root;
      q.push(nxt[root][i]);
    }
  }
  while (!q.empty()) {
    int tmp = q.front();
    q.pop();
    val[tmp] += val[fail[tmp]];
    for (int i = 0; i < m; i++) {
      if (nxt[tmp][i] == -1) {
        nxt[tmp][i] = nxt[fail[tmp]][i];
      } else {
        fail[nxt[tmp][i]] = nxt[fail[tmp]][i];
        q.push(nxt[tmp][i]);
      }
    }
  }
}
void UPD(long long &x, long long y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
long long dp[210][210][510];
long long dfs(int p, int sta, int v, int zero, int sameL, int sameR) {
  if (v > k) return 0;
  if (p == -1) return 1;
  if (!sameL && !sameR) {
    if (dp[p][sta][v] != -1) return dp[p][sta][v];
  }
  long long ret = 0;
  for (int i = ((sameL) ? l[p] : 0); i < ((sameR) ? r[p] + 1 : m); i++) {
    int newL, newR, newU = sta;
    if (sameL)
      newL = (i == l[p]);
    else
      newL = 0;
    if (sameR)
      newR = (i == r[p]);
    else
      newR = 0;
    if (!zero || i) newU = nxt[sta][i];
    long long d = dfs(p - 1, newU, v + val[newU], zero && (i == 0), newL, newR);
    UPD(ret, d);
  }
  if (!(sameL || sameR)) dp[p][sta][v] = ret;
  return ret;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  cout << dfs(lenR - 1, 0, 0, 1, 1, 1) << endl;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  scanf("%d", &lenL);
  for (int i = 0; i < lenL; i++) scanf("%d", &l[i]);
  scanf("%d", &lenR);
  for (int i = 0; i < lenR; i++) scanf("%d", &r[i]);
  reverse(l, l + lenL);
  reverse(r, r + lenR);
  cnt = 0;
  int root = NewTrie();
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    Insert(root, x);
  }
  Build(root);
  solve();
  return 0;
}
