#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[1000010];
map<string, bool> M;
string sub[100010];
int num = 0;
bool vis[100010];
char str1[100010], str2[100010];
int P[100010];
bool MEET(int which, string p, int l, int r) {
  int cnt = 0;
  if (sub[which].size() <= p.size()) {
    for (int i = 0; i < p.size(); i++) str1[i + 1] = p[i];
    for (int i = 0; i < sub[which].size(); i++) str2[i + 1] = sub[which][i];
    P[1] = 0;
    int l1 = p.size();
    int l2 = sub[which].size();
    int j = 0;
    for (int i = 2; i <= l2; i++) {
      while (j > 0 && j + 1 <= l2 && str2[j + 1] != str2[i]) j = P[j];
      if (j + 1 <= l2 && str2[j + 1] == str2[i]) j = j + 1;
      P[i] = j;
    }
    j = 0;
    for (int i = 1; i <= l1; i++) {
      while (j > 0 && j + 1 <= l2 && str2[j + 1] != str1[i]) j = P[j];
      if (j + 1 <= l2 && str2[j + 1] == str1[i]) j = j + 1;
      if (j == l2) {
        j = P[j];
        cnt++;
      }
    }
  }
  return (cnt <= r && cnt >= l);
}
int main() {
  int Cas = 0;
  while (scanf("%s", str) != EOF) {
    memset(vis, true, sizeof(vis));
    M.clear();
    int len = strlen(str);
    num = 0;
    for (int i = 0; i < len; i++) {
      string temp = "";
      for (int l = 1; l <= len; l++) {
        if (i + l - 1 >= len) break;
        int ed = i + l - 1;
        temp += str[ed];
        if (!M[temp]) {
          M[temp] = 1;
          num++;
          sub[num] = temp;
        }
      }
    }
    scanf("%d", &n);
    string p;
    int l, r;
    int ans = num;
    for (int i = 1; i <= n; i++) {
      cin >> p >> l >> r;
      for (int j = 1; j <= num; j++)
        if (vis[j])
          if (!MEET(j, p, l, r)) {
            vis[j] = false;
            ans--;
          }
    }
    cout << ans << endl;
  }
}
