#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e3 + 10;
int n, m, L[N], R[N], len[N];
char S[20][N];
int SA[N], LCP[N];
int cnt[20][N];
bool Comparator(int x, int y) { return strcmp(S[0] + x, S[0] + y) == -1; }
vector<int> ZFunction(string S) {
  int n = (int)S.size();
  vector<int> z(n, 0);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && S[i + z[i]] == S[z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
int main() {
  scanf("%s", S[0] + 1);
  n = strlen(S[0] + 1);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%s%d%d", S[i] + 1, &L[i], &R[i]);
    len[i] = strlen(S[i] + 1);
  }
  for (int i = 1; i <= n; ++i) SA[i] = i;
  sort(SA + 1, SA + 1 + n, Comparator);
  for (int i = 2; i <= n; ++i) {
    int x = n - SA[i - 1] + 1;
    int y = n - SA[i] + 1;
    while (LCP[i] < x && LCP[i] < y &&
           S[0][SA[i - 1] + LCP[i]] == S[0][SA[i] + LCP[i]])
      LCP[i]++;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    memset(cnt, 0, sizeof cnt);
    for (int k = 1; k <= m; ++k) {
      string P = "";
      for (int j = SA[i]; j <= n; ++j) P += S[0][j];
      P += "@";
      for (int j = 1; j <= len[k]; ++j) P += S[k][j];
      vector<int> Z = ZFunction(P);
      for (int j = n - SA[i] + 2; j < (int)P.size(); ++j) cnt[k][Z[j]]++;
      for (int j = n; j >= 1; --j) cnt[k][j] += cnt[k][j + 1];
    }
    for (int j = SA[i] + LCP[i]; j <= n; ++j) {
      bool flag = true;
      for (int k = 1; k <= m; ++k) {
        int c = cnt[k][j - SA[i] + 1];
        if (L[k] <= c && c <= R[k]) continue;
        flag = false;
        break;
      }
      if (flag) ans++;
    }
  }
  printf("%d", ans);
  return 0;
}
