#include <bits/stdc++.h>
using namespace std;
char s[220], p[20][220];
int n, l[20], r[20], plen[22];
bool ok(int ls, int rs, int x, int sp) {
  for (int i = 0; i <= rs - ls; i++)
    if (s[i + ls] != p[x][sp + i]) return 0;
  return 1;
}
bool check(int ls, int rs, int x) {
  int counts = 0;
  for (int i = 0; i <= plen[x] - (rs - ls + 1); i++) {
    if (ok(ls, rs, x, i)) counts++;
  }
  return counts >= l[x] && counts <= r[x];
}
unsigned long long HASH(int ls, int rs) {
  unsigned long long hash = 0;
  for (int i = ls; i <= rs; i++) {
    hash *= 13331;
    hash += (s[i] - 'a' + 1);
  }
  return hash;
}
map<unsigned long long, bool> M;
int main() {
  cin >> s;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i] >> l[i] >> r[i];
  for (int i = 1; i <= n; i++) plen[i] = strlen(p[i]);
  int len = strlen(s), ans = 0;
  M.clear();
  for (int i = 0; i < len; i++)
    for (int j = i; j < len; j++) {
      unsigned long long hash = HASH(i, j);
      if (M[hash]) continue;
      M[hash] = 1;
      bool ok = 1;
      for (int k = 1; k <= n; k++)
        if (!check(i, j, k)) {
          ok = 0;
          break;
        }
      ans += ok;
    }
  cout << ans << endl;
}
