#include <bits/stdc++.h>
using namespace std;
string s[1000];
int a[1000], b[1000];
map<string, int> mp, Mp[1000];
set<string> Se;
int main() {
  int n, m;
  string S;
  cin >> S;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> a[i] >> b[i];
    for (int I = 1; I <= s[i].length(); I++)
      for (int j = 0; I + j <= s[i].length(); j++) {
        string ss;
        for (int y = j; y < j + I; y++) ss += s[i][y];
        if (Mp[i].find(ss) == Mp[i].end())
          Mp[i][ss] = 1;
        else
          Mp[i][ss]++;
      }
  }
  long long res = 0;
  for (int i = 1; i <= S.length(); i++)
    for (int j = 0; i + j <= S.length(); j++) {
      string ss;
      for (int y = j; y < j + i; y++) ss += S[y];
      int flag = 1;
      for (int y = 0; y < n; y++) {
        if (Mp[y].find(ss) != Mp[y].end()) {
          if (Mp[y][ss] > b[y] || Mp[y][ss] < a[y]) {
            flag = 0;
          }
        } else if (a[y] > 0) {
          flag = 0;
        }
      }
      if (flag) {
        Se.insert(ss);
      }
    }
  cout << Se.size() << endl;
  cin >> n;
}
