#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

class Matcher {
	struct PMA {
		int next[256];
		vector<int> accept;
		PMA(){ fill(next, next + 256, -1); }
	};
	vector<PMA> states;
public:
	Matcher(const vector<string> &patterns){
		// Trie Ì¶¬
		states.push_back(PMA());
		for(int i = 0; i < patterns.size(); ++i){
			int cur = 0;
			for(size_t j = 0; j < patterns[i].size(); ++j){
				char c = patterns[i][j];
				if(states[cur].next[c] < 0){
					states[cur].next[c] = static_cast<int>(states.size());
					states.push_back(PMA());
				}
				cur = states[cur].next[c];
			}
			states[cur].accept.push_back(i);
		}
		// failure link Ì¶¬
		queue<int> q;
		for(int c = 1; c < 256; ++c){
			if(states[0].next[c] >= 0){
				states[states[0].next[c]].next[0] = 0;
				q.push(states[0].next[c]);
			}else{
				states[0].next[c] = 0;
			}
		}
		while(!q.empty()){
			int t = q.front();
			q.pop();
			for(int c = 1; c < 256; ++c){
				if(states[t].next[c] >= 0){
					q.push(states[t].next[c]);
					int r = states[t].next[0];
					while(states[r].next[c] < 0){ r = states[r].next[0]; }
					states[states[t].next[c]].next[0] = states[r].next[c];
				}
			}
		}
		// ¼p^[Ìª¶ñÆµÄ\êép^[ÖÌÎ
		for(int i = 0; i < patterns.size(); ++i){
			const string &pat = patterns[i];
			for(int j = 1; j < states.size(); ++j){
				int current = j, k = 0;
				for(; k < pat.size(); ++k){
					if(states[current].next[pat[k]] < 0){ break; }
					current = states[current].next[pat[k]];
				}
				if(k == pat.size()){ states[current].accept.push_back(i); }
			}
		}
	}
	int match(const string &str, vector<int> &result, int state = 0){
		int matchCount = 0;
		for(size_t i = 0; i < str.size(); ++i){
			char c = str[i];
			while(states[state].next[c] < 0){ state = states[state].next[0]; }
			state = states[state].next[c];
			for(size_t j = 0; j < states[state].accept.size(); ++j){
				++(result[states[state].accept[j]]);
				if(++matchCount >= 2){ return state; } // âèÉí¹ÄÅK»
			}
		}
		return state;
	}
	int statesNum() const { return static_cast<int>(states.size()); }
};

map<int, int> dp[21][501][2];

const int MOD = 1000000007;

int main(){
	while(true){
		int N, M, K;
		cin >> N >> M >> K;
		if(N == 0 && M == 0 && K == 0){ break; }
		vector<int> nextWords[501];
		map<string, int> wordMap;
		vector<string> words(1);
		wordMap.insert(pair<string, int>("", 0));
		string from, to;
		for(int i = 0; i < N; ++i){
			cin >> from >> to;
			int fromIndex, toIndex;
			if(wordMap.find(from) != wordMap.end()){
				fromIndex = wordMap[from];
			}else{
				fromIndex = wordMap.size();
				wordMap[from] = fromIndex;
				words.push_back(from);
				nextWords[0].push_back(fromIndex);
			}
			if(wordMap.find(to) != wordMap.end()){
				toIndex = wordMap[to];
			}else{
				toIndex = wordMap.size();
				wordMap[to] = toIndex;
				words.push_back(to);
				nextWords[0].push_back(toIndex);
			}
			nextWords[fromIndex].push_back(toIndex);
		}
		vector<string> seasonWords(K);
		for(int i = 0; i < K; ++i){ cin >> seasonWords[i]; }
		Matcher matcher(seasonWords);
		int stateNum = matcher.statesNum();
		for(int i = 0; i < 21; ++i){
			for(int j = 0; j < 501; ++j){
				for(int k = 0; k < 2; ++k){
					dp[i][j][k].clear();
				}
			}
		}
		dp[0][0][0][0] = 1;
		vector<int> result(seasonWords.size());
		for(int i = 0; i < M; ++i){
			for(int j = 0; j < words.size(); ++j){
				for(int k = 0; k < 2; ++k){
//					for(int l = 0; l < stateNum; ++l){
					for(
						map<int, int>::iterator it = dp[i % 21][j][k].begin();
						it != dp[i % 21][j][k].end(); ++it
					){
//						if(dp[i % 21][j][k][l] == 0){ continue; }
						for(int n = 0; n < nextWords[j].size(); ++n){
							int next = nextWords[j][n];
							string &word = words[next];
							if(i + word.size() > M){ continue; }
							fill(result.begin(), result.end(), 0);
							int s = matcher.match(word, result, it->first);//l);
							int m = k + accumulate(result.begin(), result.end(), 0);
							if(m >= 2){ continue; }
							dp[(i + word.size()) % 21][next][m][s] += it->second; //dp[i % 21][j][k][l];
							dp[(i + word.size()) % 21][next][m][s] %= MOD;
						}
//						dp[i % 21][j][k][l] = 0;
					}
					dp[i % 21][j][k].clear();
				}
			}
		}
		int answer = 0;
		for(int i = 0; i < words.size(); ++i){
			for(int j = 0; j < stateNum; ++j){
				answer += dp[M % 21][i][1][j];
				answer %= MOD;
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 10000