#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
struct SAM_node {
  int len, link, t[27];
} d[1100050];
struct edge {
  int t, nxt;
} e[1600050];
int n, m, num, nw, cnt = 1, lst = 1, tmp, tt, cnte, be[1100050],
                   ap[15][1100050], l[15], r[15], al[1100050], ans;
char s[50010], c[50010];
void Insert(const int& x, const int& ri) {
  d[nw = ++cnt].len = d[lst].len + 1, tmp = lst, lst = nw, ap[ri][nw] = 1;
  while (tmp && !d[tmp].t[x]) d[tmp].t[x] = nw, tmp = d[tmp].link;
  if (!tmp)
    d[nw].link = 1;
  else {
    tt = d[tmp].t[x];
    if (d[tt].len == d[tmp].len + 1)
      d[nw].link = tt;
    else {
      d[++cnt] = d[tt], d[cnt].len = d[tmp].len + 1;
      while (tmp && d[tmp].t[x] == tt) d[tmp].t[x] = cnt, tmp = d[tmp].link;
      d[nw].link = d[tt].link = cnt;
    }
  }
}
void add(const int& x, const int& y) {
  e[++cnte].t = y, e[cnte].nxt = be[x], be[x] = cnte;
}
void dfs(const int& x) {
  for (int i = be[x]; i; i = e[i].nxt) {
    dfs(e[i].t);
    for (int j = 1; j <= num; ++j) ap[j][x] += ap[j][e[i].t];
  }
}
int main() {
  scanf("%s%d", s + 1, &num), n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) Insert(s[i] - 'a', 0);
  for (int i = 1; i <= num; ++i) {
    Insert(26, i - 1), scanf("%s%d%d", c + 1, &l[i], &r[i]), m = strlen(c + 1);
    for (int j = 1; j <= m; ++j) Insert(c[j] - 'a', i);
  }
  for (int i = 1; i <= cnt; ++i) add(d[i].link, i), al[i] = d[d[i].link].len;
  dfs(1);
  for (int i = 1, p = 1; i <= n; ++i) {
    p = d[p].t[s[i] - 'a'];
    tmp = p;
    while (tmp != 1 && al[tmp] != d[tmp].len) {
      for (int j = 1; j <= num; ++j)
        if (l[j] > ap[j][tmp] || r[j] < ap[j][tmp]) goto Skip;
      ans += max(0, min(i, d[tmp].len) - al[tmp]),
          al[tmp] = max(al[tmp], min(i, d[tmp].len));
    Skip:
      tmp = d[tmp].link;
    }
  }
  printf("%d", ans);
  return 0;
}
