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 JAVA):

Solution:
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {

    public class Node {
        Node[] next = new Node[base];
        Node link;
        boolean leaf;
        int id;
        int weight;
    }

    Node[] nodes;

    void buildAho(int[][] initData, int[] value) {
        nodes = new Node[203];
        nodes[0] = new Node();
        Node root = nodes[0];
        root.id = 0;
        int n = initData.length;
        int nodesCnt = 1;
        int free = 1;
        for (int i = 0; i < n; ++i) {
            Node cur = root;
            for (int it = 0; it < initData[i].length; ++it) {
                int c = initData[i][it];
                if (cur.next[c] == null) {
                    nodes[free] = new Node();
                    cur.next[c] = nodes[free];
                    nodes[free].id = free;
                    ++free;
                    nodesCnt++;
                }
                cur = cur.next[c];
            }
            cur.weight += value[i];
            cur.leaf = true;
        }
        Node[] q = new Node[nodesCnt];
        q[0] = root;
        int e = 1;
        for (int t = 0; t < e; ++t) {
            Node node = q[t];
            for (int c = 0; c < base; ++c) {
                if (node.next[c] == null) {
                    node.next[c] = node == root ? root : node.link.next[c];
                } else {
                    node.next[c].link = node == root ? root : node.link.next[c];
                    q[e++] = node.next[c];
                }
            }
        }

        if (e != nodesCnt) {
            throw new AssertionError();
        }

        for (int i = 1; i < e; ++i) {
            q[i].weight += q[i].link.weight;
        }
    }

    public static final int MOD = (int)1e9 + 7;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        base = in.nextInt();
        limit = in.nextInt();

        int len = in.nextInt();
        int[] L = Utils.readIntArray(in, len);

        len = in.nextInt();
        int[] R = Utils.readIntArray(in, len);
        int[][] s = new int[n][];
        value = new int[n];
        for (int i = 0; i < n; ++i) {
            len = in.nextInt();
            s[i] = new int[len];
            for (int j = 0; j < len; ++j) {
                s[i][j] = in.nextInt();
            }
            value[i] = in.nextInt();
        }
        buildAho(s, value);

        int result = f(R) - f(sub(L.clone(), base));
        if (result < 0) result += MOD;
        if (result >= MOD) result -= MOD;
        out.println(result);
    }

    int[][][][][] dp;
    int[] number;
    int[] value;
    int n;
    int len;
    int limit;
    int base;

    private int f(int[] num) {
        if (num.length == 1 && num[0] == 0) return 1;
        number = num;
        len = number.length;
        dp = new int[2][206][502][2][2];
        dp[0][0][0][1][0] = 1;

        for (int len = 0; len < number.length; ++len) {
            for (int nodeId = 0; nodeId < nodes.length; ++nodeId) {
                for (int curK = 0; curK <= limit; ++curK) {
                    for (int equalPrefix = 0; equalPrefix < 2; ++equalPrefix) {
                        for (int canHaveLeadZero = 0; canHaveLeadZero < 2; ++canHaveLeadZero) {
                            if (dp[0][nodeId][curK][equalPrefix][canHaveLeadZero] != 0) {
                                int curD = dp[0][nodeId][curK][equalPrefix][canHaveLeadZero];
                                //System.err.println("dp[" + len + "][" + nodeId + "][" + curK + "][" + equalPrefix + "][" + canHaveLeadZero + "] = " + curD);
                                int startDigit = canHaveLeadZero == 1 ? 0 : 1;
                                int endDigit = equalPrefix == 1 ? number[len] : base-1;
                                for (int i = startDigit; i <= endDigit; ++i) {
                                    int newPrefix = equalPrefix;
                                    if (i < endDigit) {
                                        newPrefix = 0;
                                    }
                                    int nextNode = nodes[nodeId].next[i].id;
                                    int newK = curK + nodes[nextNode].weight;
                                    int newLeadZero = 1;
                                    if (newK <= limit) {
                                        dp[1][nextNode][newK][newPrefix][newLeadZero] += curD;
                                        if (dp[1][nextNode][newK][newPrefix][newLeadZero] >= MOD) dp[1][nextNode][newK][newPrefix][newLeadZero] -= MOD;
                                    }
                                }
                                if (canHaveLeadZero == 0) {
                                    dp[1][nodeId][curK][0][0] += curD;
                                    if (dp[1][nodeId][curK][0][0] >= MOD) dp[1][nodeId][curK][0][0] -= MOD;
                                }
                            }
                        }
                    }
                }
            }
            for (int nodeId = 0; nodeId < nodes.length; ++nodeId) {
                for (int curK = 0; curK <= limit; ++curK) {
                    for (int equalPrefix = 0; equalPrefix < 2; ++equalPrefix) {
                        for (int canHaveLeadZero = 0; canHaveLeadZero < 2; ++canHaveLeadZero) {
                            dp[0][nodeId][curK][equalPrefix][canHaveLeadZero] = dp[1][nodeId][curK][equalPrefix][canHaveLeadZero];
                            dp[1][nodeId][curK][equalPrefix][canHaveLeadZero] = 0;
                        }
                    }
                }
            }
        }
        int res = 0;
        for (int nodeId = 0; nodeId < nodes.length; ++nodeId) {
            for (int curK = 0; curK <= limit; ++curK) {
                for (int equalPrefix = 0; equalPrefix < 2; ++equalPrefix) {
                    for (int canHaveLeadZero = 0; canHaveLeadZero < 2; ++canHaveLeadZero) {
                        res += dp[0][nodeId][curK][equalPrefix][canHaveLeadZero];
                        if (res >= MOD) res -= MOD;
                    }
                }
            }
        }
        return res;
    }

    private int[] sub(int[] l, int base) {
        for (int i = l.length-1; i >= 0; --i) {
            if (l[i] > 0) {
                --l[i];
                for (int j = i + 1; j < l.length; ++j) {
                    l[j] = base-1;
                }
                break;
            }
        }
        while (l.length > 1 && l[0] == 0) {
            l = ArrayUtils.subArray(l, 1, l.length);
        }
        return l;
    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine().trim();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}

class Utils {
    public static int[] readIntArray(InputReader in, int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        return a;
    }

}

class ArrayUtils {

    public static int[] subArray(int[] a, int start, int finish) {
        int[] result = new int[finish - start];
        for (int i = start; i < finish; ++i) {
            result[i-start] = a[i];
        }
        return result;
    }

}