#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long dp[205][205][505];
int l[205], r[205], s[205];
int lim[205];
struct Trie {
  int ch[205][25];
  int end[205], fail[205];
  int root, sz, base;
  int Node() {
    memset(ch[sz], -1, sizeof(ch[sz]));
    end[sz++] = 0;
    return sz - 1;
  }
  void init(int basem) {
    base = basem;
    sz = 0;
    root = Node();
  }
  void insert(int *buf, int val) {
    int len = buf[0];
    int now = root;
    for (int i = 1; i <= len; i++) {
      int c = buf[i];
      if (ch[now][c] == -1) {
        ch[now][c] = Node();
      }
      now = ch[now][c];
    }
    end[now] += val;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < base; i++) {
      if (ch[root][i] == -1) {
        ch[root][i] = root;
      } else {
        fail[ch[root][i]] = root;
        q.push(ch[root][i]);
      }
    }
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      end[now] += end[fail[now]];
      for (int i = 0; i < base; i++) {
        if (ch[now][i] == -1) {
          ch[now][i] = ch[fail[now]][i];
        } else {
          fail[ch[now][i]] = ch[fail[now]][i];
          q.push(ch[now][i]);
        }
      }
    }
  }
} ac;
long long dfs(int len, int sta, int val, bool f, bool lead) {
  if (len == 0) return 1LL;
  if (!f && dp[len][sta][val] != -1) return dp[len][sta][val];
  long long ans = 0;
  if (lead) {
    ans += dfs(len - 1, sta, val, f && lim[len] == 0, lead);
    if (ans >= 1000000007LL) ans -= 1000000007LL;
  } else {
    int nextval = val + ac.end[ac.ch[sta][0]];
    int nextsta = ac.ch[sta][0];
    if (nextval <= k)
      ans += dfs(len - 1, nextsta, nextval, f && lim[len] == 0, lead);
    if (ans >= 1000000007LL) ans -= 1000000007LL;
  }
  int up = f ? lim[len] : m - 1;
  for (int i = 1; i <= up; i++) {
    int nextval = val + ac.end[ac.ch[sta][i]];
    int nextsta = ac.ch[sta][i];
    if (nextval <= k) ans += dfs(len - 1, nextsta, nextval, f && i == up, 0);
    if (ans >= 1000000007LL) ans -= 1000000007LL;
  }
  if (!f && !lead) dp[len][sta][val] = ans;
  return ans;
}
long long cal(int *buf) {
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < buf[0]; ++i) {
    lim[buf[0] - i] = buf[i + 1];
  }
  return dfs(buf[0], 0, 0, 1, 1);
}
int main() {
  while (scanf("%d%d%d", &n, &m, &k) != EOF) {
    scanf("%d", &l[0]);
    for (int i = 1; i <= l[0]; i++) {
      scanf("%d", &l[i]);
    }
    for (int i = l[0]; i >= 1; i--) {
      if (l[i] == 0)
        l[i] = m - 1;
      else {
        l[i]--;
        break;
      }
    }
    scanf("%d", &r[0]);
    for (int i = 1; i <= r[0]; i++) {
      scanf("%d", &r[i]);
    }
    ac.init(m);
    for (int i = 1; i <= n; i++) {
      int val;
      scanf("%d", &s[0]);
      for (int j = 1; j <= s[0]; j++) {
        scanf("%d", &s[j]);
      }
      scanf("%d", &val);
      ac.insert(s, val);
    }
    ac.build();
    printf("%I64d\n", (cal(r) - cal(l) + 1000000007LL) % 1000000007LL);
  }
  return 0;
}
