#include<bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define reps(i,j,k) for(int i=(j);i<=(k);++i)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define sz size()


using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

template<class T> ostream & operator<<(ostream &os,const vector<T> &t){os<<"{";rep(i,t.size()){os<<t[i]<<",";}os<<"}"<<endl;return os;}
template<class T,class S> ostream& operator<<(ostream &os,const pair<T,S> &o){os<<"("<<o.X<<","<<o.Y<<")";return os;}

class Matcher{
public:
  struct PMA{
    int next[256];
    vector<int> ac;
    PMA(){fill(next,next+256,-1);}
  };
  vector<PMA> states;

  Matcher(const vector<string> &pats){
    states.pb(PMA());
    rep(i,pats.size()){
      int cur=0;
      for(const char &c:pats[i]){
	if(states[cur].next[c]<0){
	  states[cur].next[c]=states.size();
	  states.pb(PMA());
	}
	cur=states[cur].next[c];
      }
      states[cur].ac.pb(i);
    }
    queue<int> q;
    rep(c,256)if(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();
      rep(c,256)if(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];
	}
      }
    }
    for(int i=0;i<pats.size();++i){
      const string &pat=pats[i];
      rep(j,states.size())if(j){
	int cur=j,k=0;
	for(;k<pat.size();++k){
	  if(states[cur].next[pat[k]]<0) break;
	  cur=states[cur].next[pat[k]];
	}
	if(k==pat.size()){states[cur].ac.pb(i);}
      }
    }
  }
  int match(const string &str,int &res,int state=0){
    res=0;
    rep(i,str.size()){
      char c=str[i];
      while(states[state].next[c]<0){state=states[state].next[0];}
      state=states[state].next[c];
      rep(j,states[state].ac.size())
	++res;
    }
    return state;
  }
  int stateNum() const {return states.size();}
};

typedef pair<string,string> pss;
typedef vector<vector<int>> Graph;

//pos*words*aho*match
const int MD=21;
int dp[MD][500][600][2];
const ll MOD=1e9+7;

int main(){
  int e,l,m;
  while(cin>>e>>l>>m,e){
    //    cout<<e<<" "<<l<<" "<<m<<endl;
    memset(dp,0,sizeof(dp));
    vector<pss> stre(e);
    rep(i,e)
      cin>>stre[i].X>>stre[i].Y;
    vector<string> toi;
    rep(i,e){
      toi.pb(stre[i].X); toi.pb(stre[i].Y);
    }
    sort(all(toi));
    toi.erase(unique(all(toi)),toi.end());
    //cout<<toi;
    int n=toi.size();
    Graph g(n);
    rep(i,e){
      g[lower_bound(all(toi),stre[i].X)-toi.begin()].
	pb(lower_bound(all(toi),stre[i].Y)-toi.begin());
    }
    //cout<<g;

    vector<string> sea(m);
    rep(i,m)
      cin>>sea[i];
    Matcher matcher(sea);
    int vs=matcher.states.size();
    /* rep(i,vs){
      cout<<i<<":"<<endl;
      cout<<"fail:"<<matcher.states[i].next[0]<<endl;
      for(char c:string("ahnskur"))
	cout<<c<<":"<<matcher.states[i].next[c]<<endl;
      cout<<endl;
      }*/
    vector<vector<pii>> mov(n,vector<pii>(vs));
    rep(i,n)rep(j,vs){
      int res;
      int x=matcher.match(toi[i],res,j);
      mov[i][j]=pii(x,res);
    }
    //cout<<mov;
    int res;
    rep(i,n){
      int x=matcher.match(toi[i],res);
      if(res<2)
	dp[toi[i].size()][i][x][res]=1;
    }
    //cout<<l<<"*"<<e<<"*"<<vs<<"*2="<<l*e*vs*2<<endl;
    rep(pos,l){
      rep(wd,n)rep(v,vs)rep(t,2){
	for(int w:g[wd]){
	  //int x=matcher.match(toi[w],res,v);
	  //cout<<w<<","<<x<<","<<res+t<<","<<pos<<","<<wd<<","<<v<<","<<t<<endl;
	  if(mov[w][v].Y+t<2)
	    (dp[(pos+toi[w].size())%MD][w][mov[w][v].X][mov[w][v].Y+t]+=dp[pos%MD][wd][v][t])%=MOD;
	}
      }
      //rep(wd,n){rep(v,vs)cout<<"("<<dp[pos%30][wd][v][0]<<","<<dp[pos%30][wd][v][1]<<"),";cout<<endl;}cout<<endl;
      fill(dp[pos%MD][0][0],dp[pos%MD][0][0]+312*612*2,0);
    }
    ll re=0;
    rep(w,n)rep(v,vs)
      (re+=dp[l%MD][w][v][1])%=MOD;
    cout<<re<<endl;
  }
  return 0;
}

Measured memory_bytes: 53292