#include <bits/stdc++.h>
using namespace std;
namespace IO {
inline char gc() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <typename T>
inline void read(T &x) {
  x = (T)0;
  T f = 1;
  char ssd = gc();
  while (ssd < '0' || ssd > '9') f = ssd == '-' ? -1 : 1, ssd = gc();
  while (ssd >= '0' && ssd <= '9')
    x = (x << 3) + (x << 1) + (ssd - '0'), ssd = gc();
  x = x * f;
}
char OUT[1000000], *S = OUT, *T = OUT + 1000000;
char Num[1000000];
int toP;
inline void out() {
  fwrite(OUT, sizeof(char), S - OUT, stdout);
  S = OUT;
}
inline void pc(char ssd) {
  *S++ = ssd;
  if (S == T) out();
}
template <typename T>
inline void write(T x) {
  if (x == 0) pc('0');
  if (x < 0) x = -x, pc('-');
  toP = 0;
  while (x) Num[++toP] = x % 10 + '0', x /= 10;
  while (toP) pc(Num[toP--]);
}
};  // namespace IO
const int maxn = 4e5 + 10;
namespace SGT {
int sum[maxn << 5];
int ls[maxn << 5], rs[maxn << 5], Node;
inline void pushup(int NODE) { sum[NODE] = sum[ls[NODE]] + sum[rs[NODE]]; }
void change(int &NODE, int l, int r, int id) {
  if (!NODE) NODE = ++Node;
  if (l == r) {
    sum[NODE] += 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= id)
    change(ls[NODE], l, mid, id);
  else
    change(rs[NODE], mid + 1, r, id);
  pushup(NODE);
}
int query(int NODE, int l, int r, int L, int R) {
  if (L > R) return 0;
  if (!NODE || (L <= l && r <= R)) return sum[NODE];
  int re = 0;
  int mid = (l + r) >> 1;
  if (mid >= L) re += query(ls[NODE], l, mid, L, R);
  if (mid < R) re += query(rs[NODE], mid + 1, r, L, R);
  return re;
}
int merge(int root1, int root2, int l, int r) {
  if (!root1 || !root2) return root1 + root2;
  int New = ++Node;
  if (l == r) {
    sum[New] = sum[root1] + sum[root2];
    return New;
  } else {
    int mid = (l + r) >> 1;
    ls[New] = merge(ls[root1], ls[root2], l, mid);
    rs[New] = merge(rs[root1], rs[root2], mid + 1, r);
    pushup(New);
    return New;
  }
}
}  // namespace SGT
namespace Tham {
int root[maxn];
int len[maxn], fa[maxn], son[maxn][26], end = 1, tnt = 1;
inline int insert(int C, int last) {
  end = ++tnt;
  len[end] = len[last] + 1;
  while (last && son[last][C] == 0) son[last][C] = end, last = fa[last];
  if (!last) {
    fa[end] = 1;
    return end;
  }
  register int c = son[last][C];
  if (len[last] + 1 == len[c]) {
    fa[end] = c;
    return end;
  }
  len[++tnt] = len[last] + 1;
  for (register int i = 0; i < 26; i += 1) son[tnt][i] = son[c][i];
  fa[tnt] = fa[c], fa[c] = tnt;
  fa[end] = tnt;
  while (son[last][C] == c) son[last][C] = tnt, last = fa[last];
  return end;
}
}  // namespace Tham
int Len;
char ssd[maxn], S[maxn];
int head[maxn], to[maxn], nxt[maxn], tot;
inline void add(int x, int y) {
  nxt[++tot] = head[x];
  head[x] = tot;
  to[tot] = y;
}
void dfs(int now) {
  for (register int i = head[now]; i; i = nxt[i]) {
    dfs(to[i]);
    Tham::root[now] = SGT::merge(Tham::root[now], Tham::root[to[i]], 1, Len);
  }
}
int pos[maxn], id[maxn];
int main() {
  scanf("%s", S + 1);
  Len = strlen(S + 1);
  id[0] = pos[0] = 1;
  for (register int i = 1; i <= Len; i += 1)
    pos[i] = Tham::insert(S[i] - 'a', pos[i - 1]),
    SGT::change(Tham::root[pos[i]], 1, Len, i);
  for (register int i = 2; i <= Tham::tnt; i += 1) add(Tham::fa[i], i);
  dfs(1);
  int T;
  scanf("%d", &T);
  while (T--) {
    int l, r;
    scanf("%d %d %s", &l, &r, ssd + 1);
    int LL = strlen(ssd + 1), match = 0;
    for (register int i = 1; i <= LL; i += 1) {
      if (Tham::son[id[i - 1]][ssd[i] - 'a'])
        id[i] = Tham::son[id[i - 1]][ssd[i] - 'a'], match += 1;
      else
        break;
    }
    bool ccf = false;
    for (register int i = match; i >= 0; i -= 1) {
      for (register int color = (i < LL ? ssd[i + 1] - 'a' + 1 : 0); color < 26;
           color += 1)
        if (Tham::son[id[i]][color]) {
          int nxt = Tham::son[id[i]][color];
          if (SGT::query(Tham::root[nxt], 1, Len, l + i, r)) {
            for (register int j = 1; j <= i; j += 1) printf("%c", ssd[j]);
            printf("%c\n", char(color + 97));
            ccf = true;
            break;
          }
        }
      if (ccf) break;
    }
    if (!ccf) puts("-1");
  }
  return 0;
}
