#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, q;
char s[N], ans[N];
struct SAM {
  int tot, last;
  int ch[N][26], dep[N], fa[N], right[N];
  int root[N], ls[N * 30], rs[N * 30], sum[N * 30], cnt;
  void init() {
    tot = last = 1;
    memset(ch[1], 0, sizeof(ch[1]));
  }
  inline int newnode(int _dep) {
    dep[++tot] = _dep;
    memset(ch[tot], 0, sizeof(ch[tot]));
    return tot;
  }
  void add(int alp) {
    alp -= 'a';
    int u, p = newnode(dep[last] + 1);
    for (u = last; u && !ch[u][alp]; u = fa[u]) ch[u][alp] = p;
    if (!u)
      fa[p] = 1;
    else {
      int v = ch[u][alp];
      if (dep[v] == dep[u] + 1)
        fa[p] = v;
      else {
        int nv = newnode(dep[u] + 1);
        fa[nv] = fa[v];
        fa[v] = fa[p] = nv;
        memcpy(ch[nv], ch[v], sizeof(ch[v]));
        for (; u && ch[u][alp] == v; u = fa[u]) ch[u][alp] = nv;
      }
    }
    last = p;
  }
  int build(int l, int r, int p) {
    int k = ++cnt;
    if (l == r) {
      sum[k] = 1;
      return k;
    }
    int mid = l + r >> 1;
    if (p <= mid)
      ls[k] = build(l, mid, p);
    else
      rs[k] = build(mid + 1, r, p);
    sum[k] = sum[ls[k]] + sum[rs[k]];
    return k;
  }
  int merge(int x, int y) {
    if (!x || !y) return x + y;
    int k = ++cnt;
    ls[k] = merge(ls[x], ls[y]);
    rs[k] = merge(rs[x], rs[y]);
    sum[k] = sum[ls[k]] + sum[rs[k]];
    return k;
  }
  void work() {
    cnt = 0;
    int now = 1;
    for (int i = 1; i <= n; ++i) {
      now = ch[now][s[i] - 'a'];
      root[now] = build(1, n, i);
      right[now] = 1;
    }
    int a[N];
    for (int i = 1; i <= tot; ++i) a[i] = i;
    sort(a + 1, a + 1 + tot, [&](int i, int j) { return dep[i] < dep[j]; });
    for (int i = tot; i >= 2; --i) {
      right[fa[a[i]]] += right[a[i]];
      root[fa[a[i]]] = merge(root[fa[a[i]]], root[a[i]]);
    }
  }
  bool check(int k, int l, int r, int p, int q) {
    if (l > q || r < p || k == 0) return 0;
    if (l >= p && r <= q) return sum[k];
    int mid = l + r >> 1;
    return check(ls[k], l, mid, p, q) || check(rs[k], mid + 1, r, p, q);
  }
  bool solve(int x, int p, int l, int r) {
    if (l > r) return 0;
    if (p == m + 1) {
      for (int i = 0; i < 26; ++i) {
        if (ch[x][i] && check(root[ch[x][i]], 1, n, l, r)) {
          ans[p] = i + 'a';
          ans[p + 1] = 0;
          return 1;
        }
      }
      return 0;
    }
    if (ch[x][s[p] - 'a'] && solve(ch[x][s[p] - 'a'], p + 1, l + 1, r)) {
      ans[p] = s[p];
      return 1;
    }
    for (int i = s[p] - 'a' + 1; i < 26; ++i) {
      if (ch[x][i] && check(root[ch[x][i]], 1, n, l, r)) {
        ans[p] = i + 'a';
        ans[p + 1] = 0;
        return 1;
      }
    }
    return 0;
  }
} S;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  S.init();
  for (int i = 1; i <= n; ++i) S.add(s[i]);
  S.work();
  cin >> q;
  while (q--) {
    int l, r;
    scanf("%d %d %s", &l, &r, s + 1);
    m = strlen(s + 1);
    if (S.solve(1, 1, l, r))
      printf("%s\n", ans + 1);
    else
      printf("-1\n");
  }
}
