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.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class C {
    static class AhoCorasik {
        int[][] next;
        int[] parent;
        int[] fail;
        int[] mark;
        char[] to;
        int last = 0;/* root node is 0 */

        public AhoCorasik(char[][] strings, int[] value) {
            int size = 1;
            for (char[] i : strings)
                size += i.length;
            next = new int[size][26];
            parent = new int[size];
            to = new char[size];
            mark = new int[size];
            fail = new int[size];
            for (int[] i : next)
                Arrays.fill(i, -1);
            int at = 0;
            for (char[] str : strings) {
                int cnode = 0;
                for (int i = 0; i < str.length; i++) {
                    if (next[cnode][str[i]] == -1) {
                        next[cnode][str[i]] = ++last;
                        parent[next[cnode][str[i]]] = cnode;
                        to[next[cnode][str[i]]] = (char) (str[i]);
                    }
                    cnode = next[cnode][str[i]];
                }
                mark[cnode] += value[at++];
            }
            Queue<Integer> Q = new ArrayDeque<Integer>();
            Q.add(0);
            while (!Q.isEmpty()) {
                int node = Q.poll();
                for (int j : next[node])
                    if (j != -1)
                        Q.add(j);
                if (node == 0)
                    continue;
                int f = fail[parent[node]];
                while (f != 0 && next[f][to[node]] == -1)
                    f = fail[f];
                f = next[f][to[node]];
                if (f == node || f == -1)
                    f = 0;
                fail[node] = f;
                mark[node] = mark[node] + mark[fail[node]];
            }
        }

        public int next(int node, char c) {
            while (node > 0 && next[node][c] == -1)
                node = fail[node];
            return (next[node][c] == -1) ? 0 : next[node][c];
        }
    }

    static int n, m, k;
    static int[] l, r;

    static int[][][][] dp;
    static AhoCorasik automata;
    static int MOD = 1000000007;
    static int src;

    static int f(int i, int state, int kval, int flags) {
        if (kval > k)
            return 0;
        if (i == r.length)
            return 1;
        if (dp[flags][i][state][kval] != -1)
            return dp[flags][i][state][kval];
        int lower = (flags & 1) != 0 ? 0 : l[i];
        int upper = (flags & 2) != 0 ? m - 1 : r[i];
        int result = 0;
        for (int j = lower; j <= upper; j++) {
            int nflags = flags;
            if (j > lower)
                nflags |= 1;
            if (j < upper)
                nflags |= 2;
            if (j != 0)
                nflags |= 4;
            int next = (j != 0 || (flags & 4) != 0) ? automata.next(state,
                    (char) j) : state;
            result += f(i + 1, next, kval + automata.mark[next], nflags);
            result %= MOD;
        }
        return dp[flags][i][state][kval] = result;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strtok = new StringTokenizer(in.readLine());
        n = Integer.parseInt(strtok.nextToken());
        m = Integer.parseInt(strtok.nextToken());
        k = Integer.parseInt(strtok.nextToken());
        strtok = new StringTokenizer(in.readLine());
        l = new int[Integer.parseInt(strtok.nextToken())];
        for (int i = 0; i < l.length; i++)
            l[i] = Integer.parseInt(strtok.nextToken());
        strtok = new StringTokenizer(in.readLine());
        r = new int[Integer.parseInt(strtok.nextToken())];
        for (int i = 0; i < r.length; i++) {
            r[i] = Integer.parseInt(strtok.nextToken());
        }
        if (l.length != r.length) {
            int[] l2 = new int[r.length];
            int at = l2.length - 1;
            for (int i = l.length - 1; i >= 0; i--)
                l2[at--] = l[i];
            l = l2;
        }
        char[][] strings = new char[n][];
        int[] values = new int[n];
        for (int i = 0; i < strings.length; i++) {
            strtok = new StringTokenizer(in.readLine());
            strings[i] = new char[Integer.parseInt(strtok.nextToken())];
            for (int j = 0; j < strings[i].length; j++)
                strings[i][j] = (char) Integer.parseInt(strtok.nextToken());
            values[i] = Integer.parseInt(strtok.nextToken());
        }
        automata = new AhoCorasik(strings, values);
        dp = new int[8][r.length][automata.next.length][k + 1];
        for (int[][][] a : dp)
            for (int[][] b : a)
                for (int[] c : b)
                    Arrays.fill(c, -1);
        int result = f(src, 0, 0, 0);
        System.out.println(result);
    }
}