#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T Abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
template <typename T>
inline void relaxMin(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
inline void relaxMax(T &a, T b) {
  if (b > a) a = b;
}
const int INF = (int)1E9;
const long double EPS = 1E-6;
const long double PI = 3.1415926535897932384626433832795;
char s[100500];
char w[10][100500];
int w_len[10];
int lw[10], rw[10];
char buf[100500];
int pi[100500];
void build_pi() {
  int n = strlen(buf);
  pi[0] = 0;
  for (int i = 1; i < n; ++i) {
    int j = pi[i - 1];
    while (j > 0 && buf[i] != buf[j]) j = pi[j - 1];
    if (buf[i] == buf[j]) ++j;
    pi[i] = j;
  }
}
int ok[100500];
int cnt[100500];
const int base = 13331, Q1 = 1000000007, Q2 = 1000000009;
int hash1[1000001], hash2[1000001], power1[1000001], power2[1000001];
bool check(int a, int b, int l) {
  int t1 = ((hash1[a + l] - (long long)hash1[a] * power1[l]) % Q1 + Q1) % Q1;
  int t2 = ((hash1[b + l] - (long long)hash1[b] * power1[l]) % Q1 + Q1) % Q1;
  if (t1 != t2) return t1 < t2;
  int t3 = ((hash2[a + l] - (long long)hash2[a] * power2[l]) % Q2 + Q2) % Q2;
  int t4 = ((hash2[b + l] - (long long)hash2[b] * power2[l]) % Q2 + Q2) % Q2;
  if (t3 != t4) return t3 < t4;
  return true;
}
void build_hash() {
  int n = strlen(s);
  hash1[0] = hash2[0] = 0;
  for (int i = 0; i < n; i++) {
    hash1[i + 1] = ((long long)hash1[i] * base + s[i]) % Q1;
    hash2[i + 1] = ((long long)hash2[i] * base + s[i]) % Q2;
  }
  power1[0] = power2[0] = 1;
  for (int i = 1; i <= n; i++) {
    power1[i] = (long long)power1[i - 1] * base % Q1;
    power2[i] = (long long)power2[i - 1] * base % Q2;
  }
}
pair<int, int> get_hash(int a, int l) {
  int t1 = ((hash1[a + l] - (long long)hash1[a] * power1[l]) % Q1 + Q1) % Q1;
  int t3 = ((hash2[a + l] - (long long)hash2[a] * power2[l]) % Q2 + Q2) % Q2;
  return make_pair(t1, t3);
}
vector<vector<pair<int, int> > > ans;
void solve() {
  scanf("%s", s);
  build_hash();
  int n;
  scanf("%d", &n);
  for (int i(0), _bb(n); i < _bb; ++i) {
    scanf("%s %d %d", w[i], &lw[i], &rw[i]);
    w_len[i] = strlen(w[i]);
  }
  int l = strlen(s);
  ans.resize(l + 1);
  for (int st = 0; st < l; st++) {
    int len = l - st;
    strcpy(buf, s + st);
    buf[len] = '#';
    for (int i(0), _bb(len + 1); i < _bb; ++i) ok[i] = 1;
    for (int i(0), _bb(n); i < _bb; ++i) {
      strcpy(buf + len + 1, w[i]);
      build_pi();
      for (int j(0), _bb(len + 1); j < _bb; ++j) cnt[j] = 0;
      for (int j(0), _bb(w_len[i]); j < _bb; ++j) {
        int v = pi[len + 1 + j];
        cnt[v]++;
      }
      for (int j(0), _bb(len + 1); j < _bb; ++j)
        if (cnt[j] < lw[i] || cnt[j] > rw[i]) {
          ok[j] = 0;
        }
    }
    for (int i(1), _bb(len + 1); i < _bb; ++i)
      if (ok[i]) {
        ans[i].push_back(get_hash(st, i));
      }
  }
  int my_ans = 0;
  for (int i(0), _bb(l + 1); i < _bb; ++i) {
    sort(ans[i].begin(), ans[i].end());
    my_ans += unique(ans[i].begin(), ans[i].end()) - ans[i].begin();
  }
  cout << my_ans << endl;
}
int main() {
  srand(0xA1B2C3D4);
  solve();
  return 0;
}
