#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
int n;
string p;
string s[MAXN];
int a[MAXN], b[MAXN];
map<string, bool> ma;
int cal(string x, string y) {
  int id = y.find(x);
  int ans = 0;
  while (id != -1) {
    ans++;
    int len = y.size();
    y = y.substr(id + 1, len);
    id = y.find(x);
  }
  return ans;
}
bool solve(string now) {
  if (ma[now]) return false;
  ma[now] = true;
  for (int i = 1; i <= n; i++) {
    int t = cal(now, s[i]);
    if (t < a[i] || t > b[i]) return false;
  }
  return true;
}
int main() {
  bool has = false;
  while (cin >> p) {
    ma.clear();
    has ? puts("") : has = true;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) cin >> s[i] >> a[i] >> b[i];
    int ans = 0;
    int lenp = p.size();
    for (int len = 1; len <= lenp; len++) {
      for (int i = 0; i < lenp; i++) {
        string now = "";
        if (i + len > lenp) break;
        for (int j = 0; j < len; j++) now += p[i + j];
        if (solve(now)) ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
