#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e2 + 10, pr = 29;
const long long md = 1ll * 1000000000000037;
int n, ted, lft[20], rgt[20];
long long dpt[10][maxn][maxn], dp[maxn][maxn];
string s, t[20];
map<long long, int> mp[20][maxn], mark[maxn];
void make_hash() {
  for (int i = 0; i < n; i++) {
    for (int l = 0; l < t[i].size(); l++) {
      dpt[i][l][l] = 1ll * (t[i][l] - 'a') % md;
      mp[i][1][dpt[i][l][l]]++;
      for (int r = l + 1; r < t[i].size(); r++) {
        dpt[i][l][r] =
            1ll *
            ((1ll * dpt[i][l][r - 1] * pr) % md + (1ll * (t[i][r] - 'a'))) % md;
        mp[i][r - l + 1][dpt[i][l][r]]++;
      }
    }
  }
}
void count_ted(long long val1, int id) {
  if (n == 0) {
    if (mark[id][val1] == 0) ted++;
    mark[id][val1] = 1;
    return;
  }
  bool ch = true;
  for (int i = 0; i < n; i++)
    if (!(lft[i] <= mp[i][id][val1] && mp[i][id][val1] <= rgt[i])) ch = false;
  if (ch) {
    ted++;
    for (int i = 0; i < n; i++) mp[i][id][val1] = -1;
  }
}
void count_hash() {
  for (int i = 0; i < s.size(); i++) {
    dp[i][i] = 1ll * (s[i] - 'a') % md;
    count_ted(dp[i][i], 1);
    for (int j = i + 1; j < s.size(); j++) {
      dp[i][j] = 1ll * ((1ll * (dp[i][j - 1] * pr) % md) + (s[j] - 'a')) % md;
      count_ted(dp[i][j], j - i + 1);
    }
  }
}
int main() {
  cin >> s >> n;
  for (int i = 0; i < n; i++) cin >> t[i] >> lft[i] >> rgt[i];
  make_hash();
  count_hash();
  cout << ted << '\n';
  return 0;
}
