#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, maxn = 205, maxm = 25, maxk = 505;
void upd(int &a, const int &b) { a = (a + b) % mod; }
int add(const int &a, const int &b) { return (a + b) % mod; }
int mul(const int &a, const int &b) { return (a * 1ll * b) % mod; }
int nxt[maxn][maxm], link[maxn], val[maxn], n, m, k, nd = 2;
void insert(vector<int> &num, int price) {
  int vr = 1;
  for (int i = 0; i < num.size(); vr = nxt[vr][num[i++]])
    if (!nxt[vr][num[i]]) nxt[vr][num[i]] = nd++;
  val[vr] += price;
}
void ac() {
  queue<int> q;
  link[1] = 1;
  for (int i = 0; i < m; i++)
    if (nxt[1][i])
      link[nxt[1][i]] = 1, q.push(nxt[1][i]);
    else
      nxt[1][i] = 1;
  while (!q.empty()) {
    int vr = q.front();
    q.pop();
    val[vr] += val[link[vr]];
    for (int i = 0; i < m; i++)
      if (nxt[vr][i])
        link[nxt[vr][i]] = nxt[link[vr]][i], q.push(nxt[vr][i]);
      else
        nxt[vr][i] = nxt[link[vr]][i];
  }
}
int dp[maxn][maxn][maxk][2];
int calculate(int len, vector<int> &num, bool eq) {
  memset(dp, 0, sizeof(dp));
  dp[0][0][0][1] = 1;
  for (int i = 0; i < len; i++) {
    for (int vr = 0; vr < nd; vr++)
      for (int cnt = 0; cnt <= k; cnt++)
        for (int fw = 0; fw < 2; fw++)
          if (dp[i][vr][cnt][fw])
            for (int d = 0; d < m; d++) {
              if (fw && d > num[i]) continue;
              int nwvr = ((!vr && d) ? nxt[1][d] : nxt[vr][d]);
              int nwcnt = min(k + 1, cnt + val[nwvr]);
              int nwfw = (fw && d == num[i]);
              upd(dp[i + 1][nwvr][nwcnt][nwfw], dp[i][vr][cnt][fw]);
            }
  }
  int ans = 0;
  for (int vr = 1; vr < nd; vr++)
    for (int cnt = 0; cnt <= k; cnt++)
      for (int fw = 0; fw <= eq; fw++) upd(ans, dp[len][vr][cnt][fw]);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  int llen, rlen;
  cin >> llen;
  vector<int> l(llen);
  for (int i = 0; i < llen; i++) cin >> l[i];
  cin >> rlen;
  vector<int> r(rlen);
  for (int i = 0; i < rlen; i++) cin >> r[i];
  for (int i = 0; i < n; i++) {
    int len, price;
    cin >> len;
    vector<int> v(len);
    for (int j = 0; j < len; j++) cin >> v[j];
    cin >> price;
    insert(v, price);
  }
  ac();
  int ans = add(calculate(rlen, r, 1), mod - calculate(llen, l, 0));
  cout << ans << "\n";
  return 0;
}
