#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long mod) {
  if (y < 0) return power(power(x, mod - 2, mod), -y, mod);
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % mod;
    y >>= 1;
    x = x * x % mod;
  }
  return res;
}
const int nn = 400010;
int N;
int l[nn], r[nn];
struct SAM {
  string S;
  int t[nn][27], pre[nn], len[nn], s[nn][12], w[nn];
  int last, siz;
  vector<int> e[nn];
  void extend(int ch, int kind) {
    int np = ++siz;
    s[np][kind]++;
    len[np] = len[last] + 1;
    e[len[np]].push_back(np);
    w[np] = ch;
    int p = last;
    last = np;
    for (; !t[p][ch]; p = pre[p]) t[p][ch] = np;
    if (!p && t[p][ch] == np)
      pre[np] = 0;
    else {
      int q = t[p][ch];
      if (len[q] == len[p] + 1)
        pre[np] = q;
      else {
        int nq = ++siz;
        len[nq] = len[p] + 1;
        e[len[nq]].push_back(nq);
        w[nq] = ch;
        memcpy(t[nq], t[q], sizeof(t[q]));
        pre[nq] = pre[q];
        pre[q] = pre[np] = nq;
        for (; t[p][ch] == q; p = pre[p]) t[p][ch] = nq;
      }
    }
  }
  void dfs(int x, string s) {
    cout << s << endl;
    for (int i = 0; i < 26; ++i)
      if (t[x][i]) {
        dfs(t[x][i], s + (char)('a' + i));
      }
  }
  void build(int kind) {
    cin >> S;
    for (int i = 0; i < S.size(); ++i) extend(S[i] - 'a', kind);
    extend(26, kind);
  }
  void work() {
    long long res = 0;
    for (int i = nn - 1; i >= 0; --i)
      for (int j = 0; j < e[i].size(); ++j) {
        int x = e[i][j];
        for (int t = 0; t <= N; ++t) s[pre[x]][t] += s[x][t];
        if (!s[x][0] || w[x] == 26) continue;
        int flag = 1;
        for (int t = 1; t <= N; ++t) {
          if (!(l[t] <= s[x][t] && s[x][t] <= r[t])) {
            flag = 0;
            break;
          }
        }
        if (flag) res += len[x] - len[pre[x]];
      }
    cout << res << endl;
  }
} suf;
int main() {
  suf.build(0);
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    suf.build(i);
    scanf("%d%d", &l[i], &r[i]);
  }
  suf.work();
  return 0;
}
