func_code_string: #include <bits/stdc++.h>   std::mt19937 rng(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1e9 + 7;   const int ms = 220;   int c = 1;   int to[ms][20];   int fail[ms];   int cost[ms];   int addString(const std::vector<int> &str) {     int on = 0;     for (auto ch : str) {       if (to[on][ch] == 0) {         to[on][ch] = c++;       }       on = to[on][ch];     }     return on;   }   void buildAho() {     std::queue<int> que;     que.push(0);     while (!que.empty()) {       int on = que.front();       que.pop();       cost[on] += cost[fail[on]];       for (int i = 0; i < 20; i++) {         if (to[on][i]) {           fail[to[on][i]] = on == 0 ? 0 : to[fail[on]][i];           que.push(to[on][i]);         } else {           to[on][i] = to[fail[on]][i];         }       }     }   }   int l[ms], r[ms];   int dp[ms][ms][505];   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     int n, m, k;     std::cin >> n >> m >> k;     {       int len;       std::cin >> len;       while (len > 0) {         std::cin >> l[ms - len];         len--;       }       l[ms - 1]--;       for (int i = ms - 1; l[i] < 0; i--) {         l[i] += m;         l[i - 1]--;       }     }     {       int len;       std::cin >> len;       while (len > 0) {         std::cin >> r[ms - len];         len--;       }     }     while (n--) {       int len;       std::cin >> len;       std::vector<int> str(len);       for (auto &v : str) std::cin >> v;       int v;       std::cin >> v;       cost[addString(str)] += v;     }     buildAho();     {       for (int i = 0; i < c; i++) {         for (int j = 0; j <= k; j++) {           dp[0][i][j] = 1;         }       }       for (int i = 1; i < ms; i++) {         for (int j = 0; j < c; j++) {           for (int val = 0; val <= k; val++) {             for (int ch = 0; ch < m; ch++) {               int newState = to[j][ch];               int newCost = val - cost[newState];               if (newCost >= 0) {                 dp[i][j][val] =                     (dp[i][j][val] + dp[i - 1][newState][newCost]) % MOD;               }             }           }         }       }     }     int ans = 0;     {       bool wtf = false;       int st = 0;       int sum = k;       for (int on = 0; on < ms; on++) {         if (!wtf && r[on] == 0) {           continue;         }         for (int i = (wtf ? 0 : 1); i < r[on]; i++) {           int newState = to[st][i];           int newCost = sum - cost[newState];           if (newCost >= 0) {             ans = (ans + dp[ms - on - 1][newState][newCost]) % MOD;           }         }         st = to[st][r[on]];         sum -= cost[st];         if (wtf) {           for (int i = 1; i < m; i++) {             int newState = to[0][i];             int newCost = k - cost[newState];             if (newCost >= 0) {               ans = (ans + dp[ms - on - 1][newState][newCost]) % MOD;             }           }         }         wtf = true;       }       if (sum >= 0) {         ans = (ans + 1) % MOD;       }     }     {       bool wtf = false;       int st = 0;       int sum = k;       for (int on = 0; on < ms; on++) {         if (!wtf && l[on] == 0) {           continue;         }         for (int i = (wtf ? 0 : 1); i < l[on]; i++) {           int newState = to[st][i];           int newCost = sum - cost[newState];           if (newCost >= 0) {             ans = (ans - dp[ms - on - 1][newState][newCost]) % MOD;           }         }         st = to[st][l[on]];         sum -= cost[st];         if (wtf) {           for (int i = 1; i < m; i++) {             int newState = to[0][i];             int newCost = k - cost[newState];             if (newCost >= 0) {               ans = (ans - dp[ms - on - 1][newState][newCost]) % MOD;             }           }         }         wtf = true;       }       if (wtf && sum >= 0) {         ans = (ans - 1 + MOD) % MOD;       }     }     ans = (ans % MOD + MOD) % MOD;     std::cout << ans << std::endl;   }   