#include <bits/stdc++.h>
using namespace std;
int l[100], r[100];
struct suffixautomata {
  struct Node {
    int deep, fail, val[12], next[38];
    long long cnt;
    void clear() {
      deep = fail = 0;
      cnt = 0;
      memset(next, 0, sizeof(next));
      memset(val, 0, sizeof(val));
    }
  };
  int size, endp;
  Node node[2 * 560000];
  int cnt[2 * 560000], st[2 * 560000];
  void init() {
    for (int i = 0; i < 38; i++) node[0].next[i] = 1;
    node[0].deep = -1;
    node[1].clear();
    size = 2;
    endp = 1;
  }
  void insert(int c, int id) {
    int p, p1, p2;
    p = size++;
    node[p].clear();
    node[p].deep = node[endp].deep + 1;
    while (node[endp].next[c] == 0) {
      node[endp].next[c] = p;
      endp = node[endp].fail;
    }
    p1 = node[endp].next[c];
    if (node[p1].deep == node[endp].deep + 1)
      node[p].fail = p1;
    else {
      p2 = size++;
      node[p2] = node[p1];
      node[p].fail = node[p1].fail = p2;
      node[p2].deep = node[endp].deep + 1;
      while (node[endp].next[c] == p1) {
        node[endp].next[c] = p2;
        endp = node[endp].fail;
      }
    }
    endp = p;
  }
  void make(char *a) {
    int i, x, j, k, len;
    len = strlen(a);
    for (i = 0; i < len; i++) {
      if ('a' <= a[i] && a[i] <= 'z')
        insert(a[i] - 'a', i);
      else
        insert(26 + a[i] - 'A', i);
    }
    for (i = 0; i <= len; i++) cnt[i] = 0;
    for (i = 1; i < size; i++) cnt[node[i].deep]++;
    for (i = 1; i <= len; i++) cnt[i] += cnt[i - 1];
    for (i = 1; i < size; i++) st[cnt[node[i].deep]--] = i;
    for (i = size - 1; i > 0; i--) {
      x = st[i];
      for (k = 0; k < 26; k++) {
        if (node[x].next[k] == 0) continue;
        for (j = 0; j < 12; j++) node[x].val[j] += node[node[x].next[k]].val[j];
      }
      for (k = 0; k < 12; k++) {
        if (node[x].next[26 + k] == 0) continue;
        node[x].val[k]++;
      }
    }
    node[1].cnt = 1;
    for (i = 1; i < size; i++) {
      x = st[i];
      for (k = 0; k < 26; k++) {
        if (node[x].next[k] == 0) continue;
        node[node[x].next[k]].cnt += node[x].cnt;
      }
    }
  }
  long long visit(int n) {
    int i, j, u, v;
    long long ans = 0;
    for (i = 2; i < size; i++) {
      if (node[i].val[0] == 0) continue;
      for (j = 0; j < n; j++) {
        if (node[i].val[j + 1] < l[j] || node[i].val[j + 1] > r[j]) break;
      }
      if (j == n) ans += node[i].cnt;
    }
    return ans;
  }
};
suffixautomata sam;
char str[560000], pat[560000];
int main() {
  int n, i;
  char tmp[100];
  scanf("%s", str);
  tmp[0] = 'A';
  tmp[1] = 0;
  strcat(str, tmp);
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s%d%d", pat, l + i, r + i);
    strcat(str, pat);
    tmp[0] = 'A' + i + 1;
    tmp[1] = 0;
    strcat(str, tmp);
  }
  sam.init();
  sam.make(str);
  printf("%I64d\n", sam.visit(n));
  return 0;
}
