#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 228228;
string a, b[N], c;
map<string, int> M;
vector<int> e[11];
int l[N], k, r[N], i, j, n, m;
int add(int p) {
  int i, j, k, ok = 1;
  for (i = 0; i < m; i++) {
    k = 0;
    for (j = 0; j < e[i].size(); j++)
      if (b[i][e[i][j]] == a[p]) e[i][k] = e[i][j] + 1, k++;
    e[i].resize(k);
    if (k < l[i] || k > r[i]) ok = 0;
  }
  return ok;
}
int main() {
  cin >> a, n = a.size();
  cin >> m;
  for (i = 0; i < m; i++) cin >> b[i] >> l[i] >> r[i];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      e[j].clear();
      for (k = 0; k < b[j].size(); k++) e[j].push_back(k);
    }
    for (j = i, c = a[j]; j < n; j++, c += a[j])
      if (add(j)) M[c] = 1;
  }
  cout << M.size() << "\n";
}
