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.*;
import java.math.*;
import java.util.*;

public class Main {
    static int T = 201;
    static int MOD = (int)1e9 + 7;

    int b, m;
    int[] value;
    int[][] go;
    Integer[][][][] memory;

    int go(int[] number, int less, int first, int length, int state, int left) {
        if (left < 0) {
            return 0;
        }
        if (length == 0) {
            return less;
        }
        if (less == 1 && memory[first][length][state][left] != null) {
            return memory[first][length][state][left];
        }
        int result = 0;
        int newLess = less;
        for (int i = less == 1 ? b - 1 : number[length - 1]; i >= first; -- i) {
            int v = go[state][i];
            result += go(number, newLess, 0, length - 1, v, left - value[v]);
            if (result >= MOD) {
                result -= MOD;
            }
            newLess = 1;
        }
        if (less == 1) {
            memory[first][length][state][left] = result;
        }
        return result;
    }

    int count(int[] number) {
        int length = number.length;
        int result = 0;
        for (int i = 1; i <= length; ++ i) {
            result += go(number, i < length ? 1 : 0, 1, i, 0, m);
            if (result >= MOD) {
                result -= MOD;
            }
        }
        return result;
    }

    public void run() {
        try {
            int n = reader.nextInt();
            b = reader.nextInt();
            m = reader.nextInt();
            int[] low;
            if (true) {
                int length = reader.nextInt();
                low = new int[length];
                for (int i = length - 1; i >= 0; -- i) {
                    low[i] = reader.nextInt();
                }
            }
            int[] high;
            if (true) {
                int length = reader.nextInt();
                high = new int[length];
                for (int i = length - 1; i >= 0; -- i) {
                    high[i] = reader.nextInt();
                }
                int delta = 1;
                for (int i = 0; i < length; ++ i) {
                    high[i] += delta;
                    delta = 0;
                    if (high[i] >= b) {
                        delta ++;
                        high[i] -= b;
                    }
                }
                if (delta > 0) {
                    high = Arrays.copyOf(high, length + 1);
                    high[length] = delta;
                }
            }
            int t = 1;
            go  = new int[T][b];
            for (int i = 0; i < T; ++ i) {
                Arrays.fill(go[i], -1);
            }
            value = new int[T];
            for (int i = 0; i < n; ++ i) {
                int length = reader.nextInt();
                int p = 0;
                for (int k = 0; k < length; ++ k) {
                    int c = reader.nextInt();
                    if (go[p][c] == -1) {
                        go[p][c] = t ++;
                    }
                    p = go[p][c];
                }
                int v = reader.nextInt();
                value[p] += v;
            }
            if (true) {
                int[] next = new int[T];
                Queue <Integer> queue = new LinkedList <Integer>();
                for (int i = 0; i < b; ++ i) {
                    int v = go[0][i];
                    if (v == -1) {
                        go[0][i] = 0;
                    } else {
                        next[v] = 0;
                        queue.offer(v);
                    }
                }
                while (!queue.isEmpty()) {
                    int u = queue.poll();
                    value[u] += value[next[u]];
                    for (int i = 0; i < b; ++ i) {
                        int v = go[u][i];
                        if (v == -1) {
                            go[u][i] = go[next[u]][i];
                        } else {
                            next[v] = go[next[u]][i];
                            queue.offer(v);
                        }
                    }
                }
            }
            memory = new Integer[2][T][T][m + 1];
            writer.println((count(high) + MOD - count(low)) % MOD);
        } catch (IOException ex) {
        }
        writer.close();
    }

    Main() {
        reader = new InputReader(System.in);
        writer = new PrintWriter(System.out);
    }

    public static void main(String[] args) {
        new Main().run();
    }

    private void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    private InputReader reader;
    private PrintWriter writer;
}

class InputReader {
    InputReader(InputStream in) {
        reader    = new BufferedReader(new InputStreamReader(in));
        tokenizer = new StringTokenizer("");
    }

    private String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private BufferedReader  reader;
    private StringTokenizer tokenizer;
}