#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010

/* Aho Corasick */

struct ACNode;

ACNode *pos[SIZE*60] = {};
int pos_size = 0;

struct ACNode{
  int val, id;
  ACNode *next[26], *failure;
  
  ACNode():val(0) { memset(next,0,sizeof(next)); }
  
  void insert(char *s){
    if(!*s){ val++; return; }
    int al = *s-'a';
    if(next[al]==NULL){
      next[al] = new ACNode;
      next[al]->id = pos_size;
      pos[pos_size++] = next[al];
    }
    next[al]->insert(s+1);
  }
  
  ACNode *nextNode(char c){
    int al = c - 'a';
    if (next[al]) return next[al];
    return failure == this ? this : failure->nextNode(c);
  }
};

struct AhoCorasick{
  ACNode *node;
  
  AhoCorasick(){node = new ACNode;}
  
  void insert(char *s) {
    node->insert(s);
  }
  
  void build() {
    queue<ACNode*> que;
    que.push(node);
    node->failure = node;
    
    while(que.size()){
      ACNode *p = que.front();
      que.pop();
      
      for(int i=0;i<26;i++){
        if(p->next[i]){
          ACNode *failure = p->failure;
          while(!failure->next[i] && failure != node){
            failure = failure->failure;
          }
          if (failure->next[i] && failure != p){
            p->next[i]->failure = failure->next[i];
            p->next[i]->val += failure->next[i]->val;
          }else{
            p->next[i]->failure = node;
          }
          que.push(p->next[i]);
        }
      }
    }
  }
};


struct DATA{
  int now;
  int acpos;
  bool usessword;

  DATA(int now = 0, int acpos = 0, bool usessword = false):now(now),acpos(acpos),usessword(usessword){}
  
  bool operator<(const DATA &b) const {
    if(now != b.now) return now < b.now;
    if(acpos != b.acpos) return acpos < b.acpos;
    return (int)usessword < (int)b.usessword;
  }
};

int n,m,q;
string from[SIZE], to[SIZE];
int fromid[SIZE], toid[SIZE];
string word[SIZE];
char ssword[50];

bool solve(){
  map<string, int> dict;
  int dictid = 0;
  vector<int> way[SIZE];

  cin >> n >> m >> q;
  
  if(n == 0) return false;

  for(int i=0;i<n;i++){
    cin >> from[i] >> to[i];

    if(dict.find(from[i]) == dict.end()){
      word[dictid] = from[i];
      dict[from[i]] = dictid++;
    }
    if(dict.find(to[i]) == dict.end()){
      word[dictid] = to[i];
      dict[to[i]] = dictid++;
    }

    fromid[i] = dict[from[i]];
    toid[i] = dict[to[i]];

    way[fromid[i]].push_back(toid[i]);
  }

  AhoCorasick ac;
  pos[pos_size++] = ac.node;
  ac.node->id = 0;
  
  for(int i=0;i<q;i++){
    cin >> ssword;
    ac.insert(ssword);
  }
  
  ac.build();

  for(int i=0;i<(int)dict.size();i++){
    way[(int)dict.size()].push_back(i);
  }
  
  map<DATA,ll> data[501];
  DATA initData = DATA((int)dict.size(), 0, false);
  data[0][initData] = 1;
  
  for(int i=0;i<m;i++){
    for(const pair<DATA,ll> &it: data[i]){
      auto p = it.first;
      ll val = it.second;

      for(int j=0;j<(int)way[p.now].size();j++){
        int l = word[way[p.now][j]].size();
        if(i + l <= m){
          ACNode *acpos = pos[p.acpos];
          int v = 0;
          for(int k=0;k<l;k++){
            acpos = acpos->nextNode(word[way[p.now][j]][k]);
            v += acpos->val;
          }

          if(v + p.usessword <= 1){
            DATA newdata = DATA(way[p.now][j], acpos->id, v+p.usessword > 0);
            data[i+l][newdata] = (data[i+l][newdata] + val)%mod;
          }
        }
      }
    }
  }

  ll ans = 0;
  
  for(const pair<DATA,ll> it: data[m]){
    if(it.first.usessword)
      ans = (it.second + ans)%mod;
  }

  printf("%lld\n", ans);
  
  return true;
}

int main(){
  while(solve()){
    for(int i=0;i<pos_size;i++){
      free(pos[i]);
    }
    pos_size = 0;
  }
  
  return 0;
}



Measured memory_bytes: 200956