#include <bits/stdc++.h>
using namespace std;
struct Node {
  int ch[26], cnt[10], fail;
  Node() {
    memset(ch, 0, sizeof(ch));
    memset(cnt, 0, sizeof(cnt));
    fail = 0;
  }
} S[1001000];
int tot = 0;
inline void insert(Node *T, char *s, int &tot) {
  int u = 0, len = strlen(s);
  for (int i = 0; i < len; ++i) {
    int x = s[i] - 'a';
    if (!T[u].ch[x]) T[u].ch[x] = ++tot;
    u = T[u].ch[x];
  }
}
inline void Getfail(Node *T) {
  queue<int> Q;
  for (int i = 0; i < 26; ++i)
    if (T[0].ch[i]) Q.push(T[0].ch[i]);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = 0; i < 26; ++i)
      if (T[u].ch[i]) {
        int j = T[u].fail;
        while (j && !T[j].ch[i]) j = T[j].fail;
        T[T[u].ch[i]].fail = T[j].ch[i];
        Q.push(T[u].ch[i]);
      }
  }
}
inline void Query(Node *T, char *s, int f) {
  int u = 0, len = strlen(s);
  for (int i = 0; i < len; ++i) {
    int x = s[i] - 'a';
    while (u && !T[u].ch[x]) u = T[u].fail;
    if (T[u].ch[x]) {
      u = T[u].ch[x];
      int j = u;
      while (j) {
        T[j].cnt[f]++;
        j = T[j].fail;
      }
    }
  }
}
char s[50010], p[50010];
int n, L[10], R[10];
long long ans;
void dfs(Node *T, int u) {
  if (u) {
    int flag = 1;
    for (int i = 0; i < n; ++i)
      if (T[u].cnt[i] < L[i] || T[u].cnt[i] > R[i]) {
        flag = 0;
        break;
      }
    ans += flag;
  }
  for (int i = 0; i < 26; ++i)
    if (T[u].ch[i]) dfs(T, T[u].ch[i]);
}
int main() {
  scanf("%s", s);
  int len = strlen(s);
  for (int i = 0; i < len; ++i) insert(S, s + i, tot);
  Getfail(S);
  ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s%d%d", p, &L[i], &R[i]);
    Query(S, p, i);
  }
  dfs(S, 0);
  cout << ans << endl;
  return 0;
}
