#include <bits/stdc++.h>
struct Aho {
  struct Node {
    size_t b, m = 0;
    std::map<size_t, size_t> A;
  };
  std::vector<Node> T{{}};
  template <typename Iter>
  void push(Iter begin, Iter end, int m) {
    size_t t = 0;
    while (begin != end) {
      if (!T[t].A.count(*begin)) {
        T[t].A[*begin] = T.size();
        T.emplace_back();
      }
      t = T[t].A[*begin++];
    }
    T[t].m += m;
  }
  void links() {
    std::vector<size_t> Q{0};
    T[0].b = 0;
    for (size_t i = 0; i < Q.size(); ++i)
      for (auto p : T[Q[i]].A) {
        size_t b = T[Q[i]].b;
        while (b && !T[b].A.count(p.first)) b = T[b].b;
        T[p.second].b = T[b].A.count(p.first) && Q[i] ? T[b].A[p.first] : b;
        T[p.second].m += T[T[p.second].b].m;
        Q.push_back(p.second);
      }
  }
  size_t step(size_t t, size_t a) {
    while (t && !T[t].A.count(a)) t = T[t].b;
    return T[t].A.count(a) ? T[t].A[a] : t;
  }
};
int alpha;
Aho aho;
enum { n_max = 220, t_max = 220, k_max = 550, M = 1000000007 };
int dyn[n_max][t_max][k_max];
int calc(int n, int t, int k) {
  if (k < 0) return 0;
  assert(n < n_max && t < aho.T.size() && k < k_max);
  int &res = dyn[n][t][k];
  if (res != -1) return res;
  if (n == 0) return res = 1;
  res = 0;
  for (int a = 0; a < (alpha); ++a) {
    int t2 = aho.step(t, a);
    res = (res + calc(n - 1, t2, k - aho.T[t2].m)) % M;
  }
  return res;
}
std::vector<int> read() {
  int l;
  scanf("%d", &l);
  std::vector<int> A(l);
  for (int &a : A) scanf("%d", &a);
  return A;
}
int go(const std::vector<int> &A, int k, bool last) {
  int res = 0;
  for (int a = 0; a < (alpha); ++a)
    if (a) {
      int t = aho.step(0, a);
      for (int n = 0; n < (A.size() - 1); ++n)
        res = (res + calc(n, t, k - aho.T[t].m)) % M;
    }
  int t = 0;
  for (int i = 0; i < (A.size()); ++i) {
    for (int a = 0; a < (A[i]); ++a)
      if (a | i) {
        int t2 = aho.step(t, a);
        res = (res + calc(A.size() - i - 1, t2, k - aho.T[t2].m)) % M;
      }
    t = aho.step(t, A[i]);
    k -= aho.T[t].m;
  }
  return res + (last && k >= 0);
}
int main() {
  int n, k;
  scanf("%d%d%d", &n, &alpha, &k);
  auto L = read(), R = read();
  while (n--) {
    auto A = read();
    int v;
    scanf("%d", &v);
    aho.push(A.begin(), A.end(), v);
  }
  aho.links();
  memset(dyn, -1, sizeof dyn);
  int res = (go(R, k, 1) - go(L, k, 0) + M) % M;
  printf("%d\n", res);
  return 0;
}
