#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200 + 10;
const int MAXK = 500 + 4;
const int MAXM = 20 + 2;
const int MOD = 1000 * 1000 * 1000 + 7;
string getNum() {
  int x;
  cin >> x;
  string s = "";
  while (x--) {
    int c;
    cin >> c;
    s += c;
  }
  return s;
}
map<string, int> val;
int n, m, kk;
map<string, int> mp;
string rev[MAXN];
int gt(const string& s) {
  int& x = mp[s];
  if (!x) x = mp.size();
  return x;
}
int nxt[MAXN][MAXM];
int v[MAXN];
int dp[MAXN][MAXN][MAXK][2];
inline void ad(int& x, const int y) {
  x += y;
  x %= MOD;
}
int cdp(string s, int tof) {
  int z = s.size();
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < z; i++)
    for (int c = (i != z - 1); c < m; c++) {
      bool b = !bool(i);
      int nj = nxt[1][c];
      if (b && c > s[i]) break;
      int nk = v[nj];
      if (nk > kk) continue;
      bool nb = (b && c == s[i]);
      ad(dp[i + 1][nj][nk][nb], 1);
    }
  for (int i = 1; i < z; i++)
    for (int j = 1; j <= mp.size(); j++)
      for (int k = 0; k <= kk; k++)
        for (int b = 0; b < 2; b++)
          if (dp[i][j][k][b])
            for (int c = 0; c < m; c++) {
              int nj = nxt[j][c];
              if (b && c > s[i]) break;
              int nk = k + v[nj];
              if (nk > kk) continue;
              bool nb = (b && c == s[i]);
              ad(dp[i + 1][nj][nk][nb], dp[i][j][k][b]);
            }
  int fans = 0;
  for (int j = 1; j <= mp.size(); j++)
    for (int k = 0; k <= kk; k++)
      for (int b = 0; b < tof; b++) ad(fans, dp[z][j][k][b]);
  return fans;
}
void pr(string s) {
  for (int i = 0; i < s.size(); i++) cout << s[i] + '0';
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> kk;
  string lb = getNum();
  string ub = getNum();
  for (int i = 0; i < n; i++) {
    string s = getNum();
    int v;
    cin >> v;
    val[s] += v;
    for (int j = 0; j <= s.size(); j++) gt(s.substr(0, j));
  }
  for (__typeof((mp).begin()) i = (mp).begin(); i != (mp).end(); i++) {
    string s = i->first;
    int& res = v[i->second];
    rev[i->second] = s;
    for (int j = 0; j < s.size(); j++) {
      string t = s.substr(j, s.size() - j);
      if (val.find(t) != val.end()) res += val[t];
    }
    for (int j = 0; j < m; j++) {
      string t = s;
      t += (char)j;
      nxt[i->second][j] = 1;
      for (int k = 0; k < t.size(); k++)
        if (mp.find(t.substr(k, t.size() - k)) != mp.end()) {
          nxt[i->second][j] = mp[t.substr(k, t.size() - k)];
          break;
        }
    }
  }
  int fans = cdp(ub, 2);
  fans -= cdp(lb, 1);
  fans += MOD;
  fans %= MOD;
  cout << fans << endl;
  return 0;
}
