#include <bits/stdc++.h>
using namespace std;
int l[15], r[15];
vector<string> V;
int Count(string small, string big) {
  if (small.size() > big.size()) return 0;
  int c = 0;
  int len1 = small.length();
  for (int i = 0; i < big.length() - len1 + 1; i++) {
    string sub = big.substr(i, len1);
    if (small == sub) c++;
  }
  return c;
}
int main() {
  string s, str;
  cin >> s;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> str;
    scanf("%d %d", &l[i], &r[i]);
    V.push_back(str);
  }
  set<string> S;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    string s2 = "";
    s2 = s2 + s[i];
    S.insert(s2);
    for (int j = i + 1; j < len; j++) {
      s2 = s2 + s[j];
      S.insert(s2);
    }
  }
  int c = 0;
  for (typeof(S.begin()) it = S.begin(); it != S.end(); it++) {
    string cur = *it;
    int flag = 1;
    for (int i = 0; i < (int)n; i++) {
      int tmp = 0;
      string now = V[i];
      int a = l[i];
      int b = r[i];
      tmp = Count(cur, now);
      if (tmp < a || tmp > b) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      c++;
    }
  }
  printf("%d", c);
  return 0;
}
