#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

struct IDM{
    map<string, int> m;
    vector<string> v;
    int get(string s){
        if(!m.count(s)){
            int k = m.size();
            m[s] = k;
            v.push_back(s);
        }
        return m[s];
    }
    string get(int k){
        return v[k];
    }
    inline int size() const { return v.size(); }
};

struct Node{
    int id;
    vector<Node*> next; 
    Node* fail;
    vector<int> match;
    Node(int id) : id(id), next(128), fail(NULL) {}
};

Node *build(vector<string> pattens, vector<Node*>& nodes){
    Node* root = new Node(0);
    nodes.push_back(root);
    root->fail = root;
    for(int i = 0; i < pattens.size(); i++){
        Node* p = root;
        for(auto c : pattens[i]){
            if(p->next[c] == 0){
                p->next[c] = new Node(nodes.size());
                nodes.push_back(p->next[c]);
            }
            p = p->next[c];
        }
        p->match.push_back(i);
    }

    queue<Node*> que;
    for(int i = 0; i < 128; i++){
        if(!root->next[i]){
            root->next[i] = root;
        }else{
            root->next[i]->fail = root;
            que.push(root->next[i]);
        }

    }
    while(!que.empty()){
        Node* p = que.front(); que.pop();
        for(int i = 0; i < 128; i++) if(p->next[i]) {
            Node* np = p->next[i];

            // add que
            que.push(np);

            // search failure link
            Node* f = p->fail;
            while(!f->next[i]) f = f->fail;
            np->fail = f->next[i];

            // update matching list
            np->match.insert(np->match.end(), np->fail->match.begin(), np->fail->match.end());
        }
    }
    return root;
}

// (node id, match count)
pair<int, int> match(Node* p, string query){
    int res = 0;
    for(int i = 0; i < query.size(); i++){
        int c = query[i];
        while(!p->next[c]) p = p->fail; 
        p = p->next[c];
        res += p->match.size();
    }
    return make_pair(p->id, res);
}

void update(int& x, int y){
    const int MOD = 1000000007;
    x = (x + y) % MOD;
}

struct State{
    int i, k, s;
    State(int i, int k, int s) :
        i(i), k(k), s(s) {}
    bool operator < (const State& st) const {
        if(i != st.i) return i < st.i;
        if(k != st.k) return k < st.k;
        return s < st.s;
    }
};


int main(){
    int N, M, K;
    while(cin >> N >> M >> K && N){
        IDM idm;
        map<int, vector<int>> next;
        REP(i, N){
            string fs, ts;
            cin >> fs >> ts;
            next[ idm.get(fs) ].push_back(idm.get(ts));
        }

        vector<string> pattens(K);
        REP(i, K) cin >> pattens[i];

        vector<Node*> nodes;
        Node* root = build(pattens, nodes);

        map<State, int> dp[501];
        // start
        for(int i = 0; i < idm.size(); i++){
            string bs = idm.get(i);
            pair<int, int> pi = match(root, bs);
            if(bs.length() <= M && pi.second < 2){
                //cout << bs.length() << " " << bs << " " << pi.first << " " << pi.second << endl;
                update(dp[ bs.length() ][ State(i, pi.first, pi.second) ], 1);
            }
        }

        // update
        for(int l = 0; l < M; l++){
            for(auto& p : dp[l]){
                int i = p.first.i, k = p.first.k, s = p.first.s;
                for(auto ni : next[i]){
                    //cout << l << " " << idm.get(i) << " " << k << " " << s << " " << dp[l][i][k][s] << endl;

                    string str = idm.get(ni);
                    pair<int, int> pi = match(nodes[k], str);
                    if(l + str.size() <= M && s + pi.second <= 1){
                        update(dp[l + str.size()][ State(ni, pi.first, s + pi.second) ], p.second);
                        /*
                           cout << "\t" << l + str.size() << " " << idm.get(ni) << " " << pi.first << " " << s + pi.second << " " << 
                           dp[l + str.size()][ ni ][ pi.first ][ s + pi.second ] << endl;
                           */
                    }
                }
            }
            dp[l].clear();
        }

        int ans = 0;
        for(auto& p : dp[M]){
            if(p.first.s == 1){
                update(ans, p.second);
            }
        }
        cout << ans << endl;

        for(auto p : nodes) delete p;
    }
    return 0;
}

Measured memory_bytes: 4680