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;
template <typename F, typename U>
ostream& operator<<(ostream& os, const pair<F, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <typename F>
ostream& operator<<(ostream& os, const vector<F>& v) {
  os << "[";
  for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i) {
    if (i != v.begin()) os << ", ";
    os << *i;
  }
  os << "]";
  return os;
}
int m;
const int MOD = 1000000007;
void add(int& a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
void read_number(vector<int>& A) {
  int el;
  scanf("%d", &el);
  A.clear();
  A.resize(el);
  for (int i = 0; i < (int)(el); ++i) scanf("%d", &A[i]);
}
int cnt_nodes = 0;
struct Node;
struct Node {
  int index, cost;
  vector<Node*> next;
  Node* fail;
  Node() : index(cnt_nodes++), cost(0), next(m, (Node*)NULL), fail(NULL) {}
};
Node* ground;
Node* root;
void add_string(const vector<int>& A, int cost) {
  Node* x = root;
  for (int i = 0; i < (int)(((int)((A).size()))); ++i) {
    if (x->next[A[i]] == NULL) x->next[A[i]] = new Node();
    x = x->next[A[i]];
  }
  x->cost += cost;
}
vector<vector<int> > F;
vector<vector<int> > C;
void compute_fail_links() {
  F.clear();
  F.resize(cnt_nodes, vector<int>(m, -1));
  C.clear();
  C.resize(cnt_nodes, vector<int>(m, 0));
  root->fail = ground;
  for (int i = 0; i < (int)(m); ++i) {
    F[ground->index][i] = root->index;
    C[ground->index][i] = 0;
  }
  queue<Node*> Q;
  Q.push(root);
  while (!Q.empty()) {
    Node* x = Q.front();
    Q.pop();
    for (int i = 0; i < (int)(m); ++i)
      if (x->next[i] != NULL) {
        Node* y = x->fail;
        while (y->next[i] == NULL) y = y->fail;
        x->next[i]->fail = y->next[i];
        x->next[i]->cost += y->next[i]->cost;
        Q.push(x->next[i]);
        F[x->index][i] = x->next[i]->index;
        C[x->index][i] = x->next[i]->cost;
      } else {
        F[x->index][i] = F[x->fail->index][i];
        C[x->index][i] = C[x->fail->index][i];
      }
  }
}
int solve(const vector<int>& V, int k) {
  vector<vector<long long> > D_lt(cnt_nodes, vector<long long>(k + 1, 0));
  vector<vector<long long> > D_eq(cnt_nodes, vector<long long>(k + 1, 0));
  vector<vector<long long> > D_gt(cnt_nodes, vector<long long>(k + 1, 0));
  D_eq[root->index][0] = 1;
  long long res = 0;
  for (int vi = 0; vi < (int)(((int)((V).size()))); ++vi) {
    vector<vector<long long> > T_lt(cnt_nodes, vector<long long>(k + 1, 0));
    vector<vector<long long> > T_eq(cnt_nodes, vector<long long>(k + 1, 0));
    vector<vector<long long> > T_gt(cnt_nodes, vector<long long>(k + 1, 0));
    for (int i = (int)(1); i <= (int)(cnt_nodes - 1); ++i)
      for (int s = (int)(0); s <= (int)(k); ++s)
        if (D_lt[i][s] || D_eq[i][s] || D_gt[i][s])
          for (int j = 0; j < (int)(m); ++j) {
            if (vi == 0 && j == 0) continue;
            int ni = F[i][j];
            int ns = s + C[i][j];
            if (ns > k) continue;
            T_lt[ni][ns] += D_lt[i][s];
            if (j < V[vi]) {
              T_lt[ni][ns] += D_eq[i][s];
            } else if (j == V[vi]) {
              T_eq[ni][ns] += D_eq[i][s];
            } else {
              T_gt[ni][ns] += D_eq[i][s];
            }
            T_gt[ni][ns] += D_gt[i][s];
          }
    for (int i = (int)(1); i <= (int)(cnt_nodes - 1); ++i)
      for (int s = (int)(0); s <= (int)(k); ++s) {
        T_lt[i][s] %= MOD;
        T_eq[i][s] %= MOD;
        T_gt[i][s] %= MOD;
        res += T_lt[i][s];
        res += T_eq[i][s];
        if (vi < ((int)((V).size())) - 1) res += T_gt[i][s];
      }
    D_lt.swap(T_lt);
    D_eq.swap(T_eq);
    D_gt.swap(T_gt);
  }
  return res % MOD;
}
int main() {
  int n, k;
  scanf("%d%d%d", &n, &m, &k);
  vector<int> U, V;
  read_number(U);
  read_number(V);
  for (int i = (int)(((int)((U).size())) - 1); i >= (int)(0); --i)
    if (U[i] > 0) {
      --U[i];
      break;
    } else {
      U[i] = m - 1;
    }
  ground = new Node();
  root = new Node();
  for (int i = 0; i < (int)(m); ++i) ground->next[i] = root;
  for (int i = 0; i < (int)(n); ++i) {
    vector<int> S;
    read_number(S);
    int cost;
    scanf("%d", &cost);
    add_string(S, cost);
  }
  compute_fail_links();
  int res = solve(V, k);
  if (!U.empty()) res = (res - solve(U, k) + MOD) % MOD;
  printf("%d\n", res);
}