#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int base, limit;
int pat[222][222];
int patval[222];
int l[222], llen;
int r[222], rlen;
class TrieNode {
 public:
  int val;
  int cache[2][2][201][501];
  TrieNode *fail;
  TrieNode *child[20];
  TrieNode *next[20];
  TrieNode() {
    val = 0;
    for (int m = 0; m < 2; m++) {
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 201; j++) {
          for (int k = 0; k < 501; k++) {
            cache[m][i][j][k] = -1;
          }
        }
      }
    }
    fail = 0;
    memset(child, 0, sizeof(child));
    memset(next, 0, sizeof(next));
  }
  ~TrieNode() {
    for (int i = 0; i < base; i++) delete child[i];
  }
  void insert(int *key, int _val) {
    if (*key == -1) {
      val += _val;
      return;
    }
    if (!child[*key]) child[*key] = new TrieNode();
    child[*key]->insert(key + 1, _val);
  }
  int calc(bool lead, bool bound, int depth, int curval) {
    if (curval > limit) return 0;
    if (depth == rlen) return 1;
    int &ret = cache[lead][bound][depth][curval];
    if (ret != -1) return ret;
    ret = 0;
    for (int i = 0; i <= (bound ? r[depth] : base - 1); i++) {
      TrieNode *tmp = lead && i == 0 ? this : (child[i] ? child[i] : next[i]);
      ret += tmp->calc(lead && i == 0, bound && (i == r[depth]), depth + 1,
                       curval + tmp->val);
      ret %= MOD;
    }
    return ret;
  }
};
void setFail(TrieNode *root) {
  root->fail = root;
  queue<TrieNode *> q;
  q.push(root);
  while (!q.empty()) {
    TrieNode *here = q.front();
    q.pop();
    for (int i = 0; i < base; i++) {
      TrieNode *child = here->child[i];
      if (!child) continue;
      if (here == root) {
        child->fail = root;
      } else {
        TrieNode *tmp = here->fail;
        while (tmp != root && !tmp->child[i]) tmp = tmp->fail;
        if (tmp->child[i]) tmp = tmp->child[i];
        child->fail = tmp;
      }
      child->val += child->fail->val;
      q.push(child);
    }
  }
}
void setNext(TrieNode *here) {
  for (int i = 0; i < base; i++) {
    TrieNode *tmp = here;
    while (tmp != tmp->fail && !tmp->child[i]) tmp = tmp->fail;
    if (tmp->child[i]) tmp = tmp->child[i];
    here->next[i] = tmp;
    if (here->child[i]) setNext(here->child[i]);
  }
}
int main() {
  int n, i, j, tmp, val, ans;
  TrieNode *head;
  scanf("%d%d%d", &n, &base, &limit);
  scanf("%d", &llen);
  for (i = 0; i < llen; i++) scanf("%d", &l[i]);
  scanf("%d", &rlen);
  for (i = 0; i < rlen; i++) scanf("%d", &r[i]);
  for (i = 0; i < n; i++) {
    scanf("%d", &tmp);
    for (j = 0; j < tmp; j++) {
      scanf("%d", &pat[i][j]);
    }
    pat[i][j] = -1;
    scanf("%d", &patval[i]);
  }
  head = new TrieNode();
  for (i = 0; i < n; i++) head->insert(pat[i], patval[i]);
  setFail(head);
  setNext(head);
  ans = head->calc(true, true, 0, 0);
  delete head;
  l[llen - 1]--;
  for (i = llen - 1; i > 0 && l[i] < 0; i--) {
    l[i - 1]--;
    l[i] += base;
  }
  rlen = llen;
  for (i = 0; i < rlen; i++) {
    r[i] = l[i];
  }
  head = new TrieNode();
  for (i = 0; i < n; i++) head->insert(pat[i], patval[i]);
  setFail(head);
  setNext(head);
  ans = (ans + MOD - head->calc(true, true, 0, 0)) % MOD;
  delete head;
  printf("%d", ans);
  return 0;
}
