Problem: Tachibana Kanade likes Mapo Tofu very much. One day, the canteen cooked all kinds of tofu to sell, but not all tofu is Mapo Tofu, only those spicy enough can be called Mapo Tofu.

Each piece of tofu in the canteen is given a m-based number, all numbers are in the range [l, r] (l and r being m-based numbers), and for every m-based integer in the range [l, r], there exists a piece of tofu with that number.

To judge what tofu is Mapo Tofu, Tachibana Kanade chose n m-based number strings, and assigned a value to each string. If a string appears in the number of a tofu, the value of the string will be added to the value of that tofu. If a string appears multiple times, then the value is also added that many times. Initially the value of each tofu is zero.

Tachibana Kanade considers tofu with values no more than k to be Mapo Tofu. So now Tachibana Kanade wants to know, how many pieces of tofu are Mapo Tofu?

Input

The first line contains three integers n, m and k (1 ≤ n ≤ 200; 2 ≤ m ≤ 20; 1 ≤ k ≤ 500). Where n denotes the number of strings, m denotes the base used, and k denotes the limit of the value for Mapo Tofu.

The second line represents the number l. The first integer in the line is len (1 ≤ len ≤ 200), describing the length (number of digits in base m) of l. Then follow len integers a1, a2, ..., alen (0 ≤ ai < m; a1 > 0) separated by spaces, representing the digits of l, with a1 being the highest digit and alen being the lowest digit.

The third line represents the number r in the same format as l. It is guaranteed that 1 ≤ l ≤ r.

Then follow n lines, each line describing a number string. The i-th line contains the i-th number string and vi — the value of the i-th string (1 ≤ vi ≤ 200). All number strings are described in almost the same format as l, the only difference is number strings may contain necessary leading zeros (see the first example). The sum of the lengths of all number strings does not exceed 200.

Output

Output the number of pieces of Mapo Tofu modulo 1000000007 (109 + 7). The answer should be a decimal integer.

Examples

Input

2 10 1
1 1
3 1 0 0
1 1 1
1 0 1


Output

97


Input

2 10 12
2 5 9
6 6 3 5 4 9 7
2 0 6 1
3 6 7 2 1


Output

635439


Input

4 2 6
6 1 0 1 1 1 0
6 1 1 0 1 0 0
1 1 2
3 0 1 0 5
4 0 1 1 0 4
3 1 0 1 2


Output

2

Note

In the first sample, 10, 11 and 100 are the only three decimal numbers in [1, 100] with a value greater than 1. Here the value of 1 is 1 but not 2, since numbers cannot contain leading zeros and thus cannot be written as "01".

In the second sample, no numbers in the given interval have a value greater than 12.

In the third sample, 110000 and 110001 are the only two binary numbers in the given interval with a value no greater than 6.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int nxt[210][22], val[210], tot = 1, fa[210], n, sg, totpow;
int sta[210], l[210], r[210], ndd[210][210], valndd[210];
long long f[210][210][510], g[210];
bool v[210][210][510];
long long predp(int cur, int lft, int pow) {
  if (pow < 0) return 0;
  if (v[cur][lft][pow]) return f[cur][lft][pow];
  v[cur][lft][pow] = true;
  if (lft == 0) {
    f[cur][lft][pow] = 1;
    return 1;
  }
  long long &nowdp = f[cur][lft][pow];
  for (int i = 0; i < sg; i++) {
    int now = nxt[cur][i];
    nowdp = nowdp + predp(now, lft - 1, pow - val[now]);
    if (nowdp > 1000000007) nowdp -= 1000000007;
  }
  return nowdp;
}
long long work(int *l) {
  long long ans = 0;
  for (int kk = 2; kk <= l[0]; kk++) {
    int cur = 1, usdpow = 0;
    for (int i = 1; i < sg; i++) {
      int now = nxt[cur][i];
      if (totpow - usdpow - val[now] >= 0)
        ans =
            (ans + f[now][l[0] - kk][totpow - usdpow - val[now]]) % 1000000007;
    }
  }
  int cur = 1, usdpow = 0;
  for (int i = 1; i <= l[0]; i++) {
    usdpow += val[cur];
    if (totpow < usdpow) break;
    for (int j = 0; j < l[i]; j++) {
      if (j == 0 && i == 1) continue;
      int now = nxt[cur][j];
      if (totpow - usdpow - val[now] >= 0)
        ans = (ans + f[now][l[0] - i][totpow - usdpow - val[now]]) % 1000000007;
    }
    cur = nxt[cur][l[i]];
  }
  usdpow += val[cur];
  if (usdpow <= totpow) ans++;
  return ans % 1000000007;
}
int main() {
  scanf("%d%d%d", &n, &sg, &totpow);
  scanf("%d", &l[0]);
  for (int i = 1; i <= l[0]; i++) scanf("%d", &l[i]);
  scanf("%d", &r[0]);
  for (int i = 1; i <= r[0]; i++) scanf("%d", &r[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ndd[i][0]);
    for (int j = 1; j <= ndd[i][0]; j++) scanf("%d", &ndd[i][j]);
    scanf("%d", &valndd[i]);
  }
  for (int i = 1; i <= n; i++) {
    int cur = 1;
    for (int j = 1; j <= ndd[i][0]; j++) {
      if (!nxt[cur][ndd[i][j]]) nxt[cur][ndd[i][j]] = ++tot;
      cur = nxt[cur][ndd[i][j]];
    }
    val[cur] += valndd[i];
  }
  int fr = 0, ta = 1;
  sta[1] = 1;
  fa[1] = 1;
  for (int i = 0; i < sg; i++)
    if (nxt[1][i]) {
      int cur = nxt[1][i];
      fa[cur] = 1;
      sta[++fr] = cur;
    } else
      nxt[1][i] = 1;
  while (ta <= fr) {
    int np = sta[ta++];
    for (int i = 0; i < sg; i++)
      if (nxt[np][i]) {
        int cur = nxt[np][i];
        fa[cur] = nxt[fa[np]][i];
        val[cur] = (val[cur] + val[fa[cur]]) % 1000000007;
        sta[++fr] = cur;
      } else
        nxt[np][i] = nxt[fa[np]][i];
  }
  long long lans = 0;
  int cur = 1;
  for (int i = 1; i <= l[0]; i++) {
    lans = lans + val[cur];
    cur = nxt[cur][l[i]];
  }
  if (lans > totpow)
    lans = 0;
  else
    lans = 1;
  int mxlen = max(l[0], r[0]) + 1;
  for (int i = 1; i <= tot; i++)
    for (int j = 0; j <= mxlen; j++)
      for (int k = 0; k <= totpow; k++)
        if (!v[i][j][k]) predp(i, j, k);
  long long clans = work(l);
  clans -= lans;
  long long rans = work(r);
  printf(
      "%I64d"
      "\n",
      (rans - clans + 1000000007) % 1000000007);
  fclose(stdin);
  fclose(stdout);
  return 0;
}