#include <bits/stdc++.h>
using namespace std;
const int MAX = 200000 + 10;
const int ALPHA = 30;
const int NUM = 12;
int T;
char a[MAX];
struct Node {
  Node *ch[ALPHA], *p;
  int cc[NUM];
  int len;
  Node() {
    memset(ch, 0, sizeof ch);
    p = 0;
    len = 0;
    memset(cc, 0, sizeof cc);
  }
}* Root = new Node;
int L[NUM], R[NUM];
vector<Node*> all;
int cmp(Node* a, Node* b) { return a->len < b->len; }
void add(Node* v, int id, int len) {
  if (v->ch[id] && v->ch[id]->len == len) return;
  Node* u = new Node;
  all.push_back(u);
  u->len = len;
  for (; v && !v->ch[id]; v = v->p) v->ch[id] = u;
  if (!v)
    u->p = Root;
  else {
    Node* nu = v->ch[id];
    if (nu->len == v->len + 1)
      u->p = nu;
    else {
      Node* nnu = new Node;
      all.push_back(nnu);
      *nnu = *nu;
      memset(nnu->cc, 0, sizeof nnu->cc);
      u->p = nnu;
      nu->p = nnu;
      nnu->len = v->len + 1;
      for (; v && v->ch[id] == nu; v = v->p) v->ch[id] = nnu;
    }
  }
  return;
}
void init(char* a, int n, int l, int r, int lab) {
  L[lab] = l;
  R[lab] = r;
  int i;
  Node* now = Root;
  for ((i) = (1); (i) <= (n); ++(i)) {
    int id = a[i] - 'a';
    add(now, id, i);
    now = now->ch[id];
    ++now->cc[lab];
  }
}
int main() {
  int i, first, second;
  scanf("%s", a + 1);
  init(a, strlen(a + 1), 1, strlen(a + 1), 0);
  scanf("%d", &T);
  for ((i) = (1); (i) <= (T); ++(i)) {
    scanf("%s%d%d", a + 1, &first, &second);
    init(a, strlen(a + 1), first, second, i);
  }
  int j;
  long long ans = 0;
  sort(all.begin(), all.end(), cmp);
  for (i = (int)all.size() - 1; i >= 0; --i) {
    int flag = 1;
    for ((j) = (0); (j) <= (T); ++(j)) {
      all[i]->p->cc[j] += all[i]->cc[j];
      flag = flag && (all[i]->cc[j] <= R[j] && all[i]->cc[j] >= L[j]);
    }
    if (flag) ans += all[i]->len - all[i]->p->len;
  }
  cout << ans << endl;
  return 0;
}
