#include <bits/stdc++.h>
using namespace std;
template <int N, int SGM>
struct SuffixAutomaton {
  int ts, whole, len[N], link[N], C[N][SGM];
  inline SuffixAutomaton() {
    memset(C, 0, sizeof(C));
    memset(len, 0, sizeof(len));
    memset(link, 0, sizeof(link));
    ts = whole = 0;
    link[0] = -1;
  }
  inline void Add(int ch) {
    int v = whole;
    whole = ++ts;
    link[whole] = 0;
    len[whole] = len[v] + 1;
    while (v >= 0 && !C[v][ch]) C[v][ch] = whole, v = link[v];
    if (v >= 0) {
      int u = C[v][ch];
      if (len[u] == len[v] + 1)
        link[whole] = u;
      else {
        ++ts;
        len[ts] = len[v] + 1;
        link[ts] = link[u];
        link[u] = link[whole] = ts;
        for (int j = 0; j < SGM; j++) C[ts][j] = C[u][j];
        while (v >= 0 && C[v][ch] == u) C[v][ch] = ts, v = link[v];
      }
    }
  }
};
const int N = 600005 * 2, SGM = 27, MXN = 11;
SuffixAutomaton<N, SGM> SA;
int n, L[MXN], R[MXN], Start[MXN], dp[N][MXN], M[N];
string S[MXN];
vector<int> Adj[N];
long long tot;
void DFS(int v) {
  if (M[v] != -1) dp[v][M[v]]++;
  for (int u : Adj[v]) {
    DFS(u);
    for (int j = 0; j <= n; j++) dp[v][j] += dp[u][j];
  }
}
int main() {
  cin >> S[0] >> n;
  memset(M, -1, sizeof(M));
  for (char ch : S[0]) SA.Add(ch - 'a'), M[SA.whole] = 0;
  L[0] = 1;
  R[0] = N;
  Start[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> S[i] >> L[i] >> R[i];
    SA.Add(26);
    Start[i] = SA.len[SA.whole];
    for (char ch : S[i]) SA.Add(ch - 'a'), M[SA.whole] = i;
  }
  for (int i = 1; i <= SA.ts; i++) Adj[SA.link[i]].push_back(i);
  DFS(0);
  for (int i = 1; i <= SA.ts; i++) {
    bool Fail = 0;
    for (int j = 0; j <= n; j++)
      if (dp[i][j] < L[j] || R[j] < dp[i][j]) Fail = 1;
    if (!Fail) tot += SA.len[i] - SA.len[SA.link[i]];
  }
  return !printf("%lld\n", tot);
}
