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;
const int mod = 1000000007;
const int inf = 0x20202020;
const double eps = 1e-9;
const double pi = 3.1415926535897932384626;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long powmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int AC_SIGMA = 20, AC_V = 22, AC_N = 2010;
struct AC_automaton {
  struct node {
    node *go[AC_V], *fail, *f;
    int fg, id;
  } pool[AC_N], *cur, *root, *q[AC_N];
  node *newnode() {
    node *p = cur++;
    memset(p->go, 0, sizeof(p->go));
    p->fail = p->f = NULL;
    p->fg = 0;
    return p;
  }
  void init() {
    cur = pool;
    root = newnode();
  }
  node *append(node *p, int w) {
    if (!p->go[w]) p->go[w] = newnode(), p->go[w]->f = p;
    return p = p->go[w];
  }
  void build() {
    int t = 1;
    q[0] = root;
    for (int i = 0; i < (int)t; i++)
      for (int j = 0; j < (int)AC_SIGMA; j++)
        if (q[i]->go[j]) {
          node *v = q[i]->go[j], *p = v->f->fail;
          while (p && !p->go[j]) p = p->fail;
          if (p)
            v->fail = p->go[j];
          else
            v->fail = root;
          q[t++] = q[i]->go[j];
        }
    for (int i = 0; i < (int)t; i++)
      if (q[i]->fail) q[i]->fg += q[i]->fail->fg;
    for (int i = 0; i < (int)t; i++)
      for (int j = 0; j < (int)AC_SIGMA; j++)
        if (!q[i]->go[j]) {
          node *p = q[i]->fail;
          while (p && !p->go[j]) p = p->fail;
          if (p)
            q[i]->go[j] = p->go[j];
          else
            q[i]->go[j] = root;
        }
  }
};
AC_automaton T;
int n, m, k, x, sz;
vector<int> l, r;
int dp[210][210][510][2];
int solve(int rem, int pos, int val, bool led) {
  if (led) pos = 0, val = 0;
  int &p = dp[rem][pos][val][led];
  if (p != -1)
    return p;
  else if (rem == 0)
    return p = (val <= k);
  else {
    p = 0;
    AC_automaton::node *c = T.pool + pos;
    for (int i = 0; i < (int)m; i++) {
      p += solve(rem - 1, c->go[i] - T.pool, min(val + c->go[i]->fg, k + 1),
                 led & (i == 0));
      if (p >= mod) p -= mod;
    }
    return p;
  }
}
int solve(vector<int> &p) {
  int rem = ((int)(p).size()), pos = 0, val = 0, led = 1;
  int ans = 0;
  for (int i = 0; i < (int)((int)(p).size()); i++) {
    AC_automaton::node *c = T.pool + pos;
    for (int j = 0; j < (int)p[i]; j++) {
      ans += solve(rem - 1, c->go[j] - T.pool, min(val + c->go[j]->fg, k + 1),
                   led & (j == 0));
      if (ans >= mod) ans -= mod;
    }
    rem -= 1;
    pos = c->go[p[i]] - T.pool;
    val = min(val + c->go[p[i]]->fg, k + 1);
    led = 0;
  }
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  scanf("%d", &sz);
  for (int i = 0; i < (int)sz; i++) {
    scanf("%d", &x);
    l.push_back(x);
  }
  scanf("%d", &sz);
  r.push_back(0);
  for (int i = 0; i < (int)sz; i++) {
    scanf("%d", &x);
    r.push_back(x);
  }
  for (int i = ((int)(r).size()) - 1; i >= 0; i--)
    if (r[i] == m - 1)
      r[i] = 0;
    else {
      r[i]++;
      break;
    }
  if (!r[0]) r.erase(r.begin());
  T.init();
  for (int i = 0; i < (int)n; i++) {
    scanf("%d", &sz);
    AC_automaton::node *p = T.root;
    for (int j = 0; j < (int)sz; j++) scanf("%d", &x), p = T.append(p, x);
    scanf("%d", &x);
    p->fg += x;
  }
  T.build();
  memset(dp, -1, sizeof(dp));
  printf("%d\n", (solve(r) - solve(l) + mod) % mod);
}