#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const int M = 2000100;
int m, l[N], r[N], pos[N], len[N], w[M], mask[2][M];
char p[11][N];
bool vis[M], ok[N][N];
map<int, int> trie[2][M];
void f(int at) {
  int n = strlen(p[at]);
  int r = min(1, at);
  len[r] = 1;
  mask[r][0] = 0;
  trie[r][0].clear();
  for (int i = 0; i < n; i++) {
    int now = 0;
    for (int j = i; j < n; j++) {
      int ch = p[at][j] - 'a';
      if ((mask[r][now] & (1 << ch)) == 0) {
        mask[r][len[r]] = 0;
        trie[r][len[r]].clear();
        w[len[r]] = 0;
        mask[r][now] |= (1 << ch);
        trie[r][now][ch] = len[r]++;
      }
      now = trie[r][now][ch];
      w[now]++;
    }
  }
}
int main() {
  scanf("%s %d", p[0], &m);
  for (int i = 1; i <= m; i++) {
    scanf("%s %d %d", p[i], &l[i], &r[i]);
  }
  f(0);
  int n = strlen(p[0]);
  memset(ok, true, sizeof ok);
  for (int k = 1; k <= m; k++) {
    f(k);
    for (int i = 0; i < n; i++) {
      pos[k] = 0;
      for (int j = i; j < n; j++) {
        int ch = p[0][j] - 'a';
        int where = pos[k];
        if (where == -1 || trie[1][where].count(ch) == 0) {
          pos[k] = -1;
        } else {
          pos[k] = trie[1][where][ch];
        }
        int many = 0;
        if (pos[k] != -1) {
          many += w[pos[k]];
        }
        if (many < l[k] || many > r[k]) {
          ok[i][j] = false;
        }
      }
    }
    for (int i = 0; i < l[1]; i++) {
      trie[1][i].clear();
    }
  }
  int res = 0;
  memset(vis, false, sizeof vis);
  for (int i = 0; i < n; i++) {
    int now = 0;
    for (int j = i; j < n; j++) {
      int ch = p[0][j] - 'a';
      now = trie[0][now][ch];
      res += ((!vis[now] && ok[i][j]) ? 1 : 0);
      vis[now] = true;
    }
  }
  printf("%d\n", res);
  return 0;
}
