#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
//#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

template<class Converter, class SuffixInfo, int NODE_NUM = 1000000>
class AhoCorasick {
public:
  using value_structure = typename Converter::value_structure;
  using size_type = std::uint64_t;
  static constexpr size_type num_of_kinds = Converter::num_of_kinds;

  using value_type = typename SuffixInfo::value_type;
  using merged_value_type = typename SuffixInfo::merged_value_type;

  struct Node {
    size_type size, end, len, faillink;
    value_type val;
    merged_value_type suf_info;
    std::array<int, num_of_kinds> ch;
    Node () : size(0), end(0), len(0), val(SuffixInfo::identity()),
              suf_info(SuffixInfo::midentity()), faillink(0) { ch.fill(-1); }
  };

private:
  std::vector<Node> node;

public:
  AhoCorasick() {
    node.reserve(NODE_NUM);
    node.push_back(Node());
  }

  void insert(const value_structure& v, size_type num = 1, value_type val = value_type(), size_type k = 0, size_type idx = 0) {
    node[idx].size += num;
    if (k == v.size()) {
      node[idx].end += num;
      node[idx].val = SuffixInfo::operation(node[idx].val, val);
      return;
    }
    size_type nxt = Converter::convert(v[k]);
    if (node[idx].ch[nxt] == -1) {
      node.push_back(Node());
      node[idx].ch[nxt] = node.size()-1;
      node.back().len = k+1;
    }
    insert(v, num, val, k+1, node[idx].ch[nxt]);
  }

  size_type count_prefix(const value_structure& v, size_type k = 0, size_type idx = 0) {
    if (v.size() == k) return node[idx].size;
    size_type nxt = Converter::convert(v[k]);
    if (node[idx].ch[nxt] == -1) return 0;
    return count_prefix(v, k+1, node[idx].ch[nxt]);
  }

  size_type count(const value_structure& v, size_type k = 0, size_type idx = 0) {
    if (v.size() == k) return node[idx].end;
    size_type nxt = Converter::convert(v[k]);
    if (node[idx].ch[nxt] == -1) return 0;
    return count(v, k+1, node[idx].ch[nxt]);
  }

  template<typename F>
  void query(const value_structure& v, const F& f, size_type k = 0, size_type idx = 0) {
    if (node[idx].size > 0) f(node[idx]);
    if (v.size() == k) return;
    size_type nxt = Converter::convert(v[k]);
    if (node[idx].ch[nxt] == -1) return;
    query(v, f, k+1, node[idx].ch[nxt]);
  }

  size_type proceed(size_type k, size_type c, bool need_convert = 1) {
    if (need_convert) c = Converter::convert(c);
    while (node[k].ch[c] == -1)  k = node[k].faillink;
    return node[k].ch[c];
  }

  void build() {
    std::queue<size_type> que;
    for (int i = 0; i < num_of_kinds; i++) {
      if (node[0].ch[i] == -1) node[0].ch[i] = 0;
      else {
        que.push(node[0].ch[i]);
        SuffixInfo::merge(node[node[0].ch[i]].suf_info, node[node[0].ch[i]].val);
      }
    }
    while (que.size()) {
      int k = que.front();
      que.pop();
      for (int i = 0; i < num_of_kinds; i++) {
        if (node[k].ch[i] == -1) continue;
        size_type nx = node[k].ch[i];
        node[nx].faillink = proceed(node[k].faillink, i, false);

        SuffixInfo::merge(node[nx].suf_info, node[nx].val);
        SuffixInfo::merge(node[nx].suf_info, node[node[nx].faillink].suf_info);
        que.push(nx);
      }
    }
  }

  const Node& operator[](size_type k) {
    return node[k];
  }

  int64 size() {
    return node.size();
  }
};

class Converter {
public:
  using value_structure = std::string;
  using value_type = typename value_structure::value_type;
  static constexpr std::size_t num_of_kinds = 26;
  static std::size_t convert(const value_type& v) {
    return v-'a';
  }
};

class SuffixInfo {
public:
  using value_type = int;
  using merged_value_type = int;
  static value_type identity() { return 0; }
  static merged_value_type midentity() { return 0; }
  static value_type operation(const value_type& a, const value_type& b) {
    return a + b;
  }
  static void merge(merged_value_type& a, const merged_value_type& b) {
    a += b;
  }
//  static void merge(merged_value_type& a, const value_type& b) {
//    a |= b;
//  }
};
template<::std::uint_fast64_t mod>
class ModInt{
private:
  using value_type = ::std::uint_fast64_t;
  value_type n;
public:
  ModInt() : n(0) {}
  ModInt(value_type n_) : n(n_ % mod) {}
  ModInt(const ModInt& m) : n(m.n) {}

  template<typename T>
  explicit operator T() const { return static_cast<T>(n); }
  value_type get() const { return n; }

  friend ::std::ostream& operator<<(::std::ostream &os, const ModInt<mod> &a) {
    return os << a.n;
  }

  friend ::std::istream& operator>>(::std::istream &is, ModInt<mod> &a) {
    value_type x;
    is >> x;
    a = ModInt<mod>(x);
    return is;
  }

  bool operator==(const ModInt& m) const { return n == m.n; }
  bool operator!=(const ModInt& m) const { return n != m.n; }
  ModInt& operator*=(const ModInt& m){ n = n * m.n % mod; return *this; }

  ModInt pow(value_type b) const{
    ModInt ans = 1, m = ModInt(*this);
    while(b){
      if(b & 1) ans *= m;
      m *= m;
      b >>= 1;
    }
    return ans;
  }

  ModInt inv() const { return (*this).pow(mod-2); }
  ModInt& operator+=(const ModInt& m){ n += m.n; n = (n < mod ? n : n - mod); return *this; }
  ModInt& operator-=(const ModInt& m){ n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
  ModInt& operator/=(const ModInt& m){ *this *= m.inv(); return *this; }
  ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; }
  ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; }
  ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; }
  ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; }
  ModInt& operator++(){ n += 1; return *this; }
  ModInt& operator--(){ n -= 1; return *this; }
  ModInt operator++(int){
    ModInt old(n);
    n += 1;
    return old;
  }
  ModInt operator--(int){
    ModInt old(n);
    n -= 1;
    return old;
  }
  ModInt operator-() const { return ModInt(mod-n); }
};
constexpr int64 mod = 1e9+7;
using Mint = ModInt<mod>;

int main(void) {
  int64 N, M, K;
  while (cin >> N >> M >> K && N+M+K) {
    map<string, int> id;
    vector<vector<int>> G;
    vector<string> vs;
    G.push_back(vector<int>());
    vs.push_back("");
    REP(i, N) {
      string from, to;
      cin >> from >> to;
      if (id.count(from) == 0) {
        id[from] = vs.size();
        vs.push_back(from); G.push_back(vector<int>());
      }
      if (id.count(to) == 0) {
        id[to] = vs.size();
        vs.push_back(to); G.push_back(vector<int>());
      }
      G[id[from]].push_back(id[to]);
    }
    FOR(i, 1, vs.size()) G[0].push_back(i);
    AhoCorasick<Converter, SuffixInfo> ah;
    REP(i, K) {
      string s;
      cin >> s;
      ah.insert(s, 1, 1);
    }
    ah.build();
    using T = tuple<int, int, int>;
    vector<map<T, Mint>> dp(M+1);
    dp[0][T(0, 0, 0)] = 1;

    REP(i, M) {
      for (auto &x : dp[i]) {
        int64 j, v, kigo;
        tie(j, v, kigo) = x.fs;
        for (auto k : G[j]) {
          int u = v;
          int sum = kigo;
          if (vs[k].size() + i > M) continue;
          REP(l, vs[k].size()) {
            u = ah.proceed(u, vs[k][l]);
            sum += ah[u].suf_info;
          }
          if (sum > 1) continue;
          dp[i+vs[k].size()][T(k, u, sum)] += x.sc;
        }
      }
    }
    Mint res = 0;
    for (auto &x : dp[M]) {
      if (get<2>(x.fs) == 1) {
        res += x.sc;
      }
    }
    cout << res << endl;
  }
}



Measured memory_bytes: 200876