#include <bits/stdc++.h>
using namespace std;
namespace {
template <class T>
void read(T& container) {
  for (typename T::value_type& x : container) cin >> x;
}
template <class T>
void print(T& container, const char separator = ' ') {
  for (typename T::value_type& x : container) cout << x << separator;
}
void openFiles(const char* in, const char* out) {
  freopen(in, "r", stdin);
  freopen(out, "w", stdout);
}
unsigned long long prime = 22801763489;
map<unsigned long long, int> goodHashes;
set<unsigned long long> curHashes;
set<unsigned long long> badHashes;
set<unsigned long long> myHashes;
set<unsigned long long> oldHashes;
map<unsigned long long, int> cnt;
const int maxn = 2500;
unsigned long long fhash[maxn];
unsigned long long pows[maxn];
string p[15];
int l[15], r[15];
void precalcPows() {
  pows[0] = 1;
  for (int i = 1; i < maxn; ++i) pows[i] = pows[i - 1] * prime;
}
bool firstTime = 1;
void hash(int pi) {
  const string& s = p[pi];
  cnt.clear();
  curHashes.clear();
  int n = s.size(), i, j;
  fhash[0] = s[0];
  for (i = 1; i < n; ++i) fhash[i] = fhash[i - 1] * prime + s[i];
  unsigned long long tmphash;
  for (i = 0; i < n; ++i)
    for (j = i; j < n; ++j) {
      tmphash = fhash[j];
      if (i > 0) tmphash -= fhash[i - 1] * pows[j - i + 1];
      if (myHashes.find(tmphash) != myHashes.end()) {
        ++cnt[tmphash];
        if (l[pi] != 0) curHashes.insert(tmphash);
      } else if (oldHashes.find(tmphash) == oldHashes.end())
        break;
    }
  if (l[pi] != 0) myHashes = curHashes;
  for (map<unsigned long long, int>::iterator it = cnt.begin(); it != cnt.end();
       ++it)
    if (!(it->second >= l[pi] && it->second <= r[pi]))
      myHashes.erase(it->first);
}
void run() {
  precalcPows();
  string s;
  int n;
  cin >> s >> n;
  int m = s.size();
  int strictIn = 0;
  fhash[0] = s[0];
  int i, j;
  for (i = 1; i < m; ++i) fhash[i] = fhash[i - 1] * prime + s[i];
  unsigned long long tmphash;
  for (i = 0; i < m; ++i)
    for (j = i; j < m; ++j) {
      tmphash = fhash[j];
      if (i > 0) tmphash -= fhash[i - 1] * pows[j - i + 1];
      myHashes.insert(tmphash);
    }
  oldHashes = myHashes;
  for (i = 0; i < n; ++i) {
    cin >> p[i] >> l[i] >> r[i];
    hash(i);
  }
  cout << myHashes.size() << endl;
}
}  // namespace
int main() {
  run();
  return 0;
}
