#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline int read();
const int M = 200016, MOD = 1000000007;
int sz;
int ch[M][26], len[M], link[M], pre[M];
void extend(const char *s) {
  for (int i = 0, lst = 0; s[i]; ++i) {
    int c = s[i] - 'a', cur = ++sz;
    len[cur] = len[lst] + 1;
    int p = lst;
    while (!ch[p][c]) ch[p][c] = cur, p = link[p];
    if (ch[p][c] != cur) {
      int q = ch[p][c];
      if (len[p] + 1 == len[q])
        link[cur] = q;
      else {
        int clone = ++sz;
        memcpy(ch[clone], ch[q], sizeof(ch[q]));
        link[clone] = link[q];
        len[clone] = len[p] + 1;
        while (ch[p][c] == q) ch[p][c] = clone, p = link[p];
        link[q] = link[cur] = clone;
      }
    }
    lst = cur;
    pre[cur] = i + 1;
  }
}
pair<int, int> qrys[M * 2 * 26];
int qcnt;
int qans[M * 2 * 26];
vector<int> sons[M];
vector<int> qry[M];
set<int> st[M];
int tar[M];
void merge(int a, int b) {
  if (st[tar[a]].size() < st[tar[b]].size()) swap(a, b);
  for (auto x : st[tar[b]]) st[tar[a]].insert(x);
  st[tar[b]].clear();
  tar[b] = tar[a];
}
void solve(int u) {
  for (auto v : sons[u]) solve(v), merge(u, v);
  for (auto qid : qry[u]) {
    int l = qrys[qid].first, r = qrys[qid].second;
    auto it = st[tar[u]].lower_bound(l);
    if (it != st[tar[u]].end() && *it <= r) qans[qid] = 1;
  }
}
char tex[M], pat[M * 2];
int lef[M], rig[M], pid[M], pln[M], pcnt;
int solved[M];
void foreach_query(int ftq, int id, int now, int tag) {
  if (pat[id] && ch[now][pat[id] - 'a'])
    foreach_query(ftq, id + 1, ch[now][pat[id] - 'a'], tag);
  for (int c = pat[id] ? pat[id] + 1 : 'a'; c <= 'z'; ++c) {
    int tmp = ch[now][c - 'a'];
    if (tmp && rig[ftq] - lef[ftq] >= id - pid[ftq]) {
      ++qcnt;
      if (tag == 0) {
        qrys[qcnt] = {lef[ftq] + id - pid[ftq], rig[ftq]};
        qry[tmp].push_back(qcnt);
      } else if (qans[qcnt] == 1 && !solved[ftq]) {
        solved[ftq] = 1;
        for (int xj = pid[ftq]; xj < id; ++xj) putchar(pat[xj]);
        putchar(c);
        printf("\n");
      }
    }
  }
}
int main(void) {
  scanf("%s", tex);
  extend(tex);
  for (int i = 1; i <= sz; ++i) sons[link[i]].push_back(i);
  for (int i = 0; i <= sz; ++i) {
    tar[i] = i;
    if (pre[i]) st[i].insert(pre[i]);
  }
  int q = read();
  for (int i = 1; i <= q; ++i) {
    lef[i] = read(), rig[i] = read(), pid[i] = pcnt;
    scanf("%s", pat + pid[i]);
    pln[i] = strlen(pat + pid[i]);
    pcnt += pln[i] + 1;
    foreach_query(i, pid[i], 0, 0);
  }
  solve(0);
  qcnt = 0;
  for (int i = 1; i <= q; ++i) {
    foreach_query(i, pid[i], 0, 1);
    if (!solved[i]) printf("-1\n");
  }
  return 0;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
