#include <bits/stdc++.h>
using namespace std;
const int N = 1110000;
int ch[N][26], prt[N], len[N], Right[N][11];
int L[21], R[21], n;
int Lst, root, node;
char s[12][51000];
int newnode(int l) {
  int x = ++node;
  len[x] = l;
  return x;
}
void Insert(int w) {
  int p = Lst, nx = newnode(len[p] + 1);
  Lst = nx;
  for (; p && !ch[p][w]; p = prt[p]) ch[p][w] = nx;
  if (!p)
    prt[nx] = root;
  else {
    int q = ch[p][w];
    if (len[q] == len[p] + 1)
      prt[nx] = q;
    else {
      int newq = newnode(len[p] + 1);
      for (int i = 0; i < 26; ++i) ch[newq][i] = ch[q][i];
      prt[newq] = prt[q];
      prt[nx] = prt[q] = newq;
      for (; p && ch[p][w] == q; p = prt[p]) ch[p][w] = newq;
    }
  }
}
vector<int> G[N];
void DFS(int u) {
  for (int i = 0; i < G[u].size(); ++i) {
    int to = G[u][i];
    DFS(to);
    for (int k = 0; k <= n; ++k) Right[u][k] += Right[to][k];
  }
}
int main() {
  scanf("%s%d", s[0], &n);
  for (int i = 1; i <= n; ++i) scanf("%s%d%d", &s[i], &L[i], &R[i]);
  root = Lst = newnode(0);
  for (int i = 0; i <= n; ++i) {
    Lst = root;
    int l = strlen(s[i]);
    for (int j = 0; j < l; ++j) {
      Insert(s[i][j] - 'a');
      Right[Lst][i]++;
    }
  }
  for (int i = 2; i <= node; ++i) G[prt[i]].push_back(i);
  DFS(root);
  long long Ans = 0;
  for (int i = 2; i <= node; ++i) {
    if (!Right[i][0]) continue;
    bool flag = 1;
    for (int k = 1; k <= n; ++k)
      if (Right[i][k] < L[k] || Right[i][k] > R[k]) {
        flag = 0;
        break;
      }
    if (flag) Ans += 1ll * (len[i] - len[prt[i]]);
  }
  cout << Ans << '\n';
  return 0;
}
