#include <bits/stdc++.h>
using std::vector;
const int N(1e5 + 10), M(2e5 + 10), maxn(2e5 + 10);
int n, q;
char s[N], t[M];
namespace Segment_Tree {
struct tree {
  bool exist;
  tree *lson, *rson;
  static tree *null;
  void *operator new(size_t size);
  inline tree() : exist(0) {
    static bool init(0);
    if (!init) init = 1, null = new tree, null->lson = null->rson = null;
    lson = rson = null;
  }
  inline const void pushup() { exist = lson->exist || rson->exist; }
} * tree::null;
char memory_pool[maxn * 40 * sizeof(tree)],
    *tail(memory_pool + sizeof memory_pool);
inline void *tree::operator new(size_t size) { return tail -= size; }
inline const void insert(tree *&p, const int &l, const int &r, const int &pos) {
  if (p == tree::null) p = new tree;
  p->exist = 1;
  if (l == r) return;
  const int mid(l + r >> 1);
  if (pos <= mid)
    insert(p->lson, l, mid, pos);
  else
    insert(p->rson, mid + 1, r, pos);
}
inline const bool query(tree *p, const int &l, const int &r, const int &L,
                        const int &R) {
  if (p == tree::null) return 0;
  if (l > R || r < L) return 0;
  if (l >= L && r <= R) return p->exist;
  const int mid(l + r >> 1);
  if (query(p->lson, l, mid, L, R)) return 1;
  return query(p->rson, mid + 1, r, L, R);
}
inline tree *merge(tree *a, tree *b, const int &l, const int &r) {
  if (a == tree::null && b == tree::null) return tree::null;
  if (a == tree::null) return b;
  if (b == tree::null) return a;
  tree *p(new tree);
  if (l == r) return p->exist = a->exist || b->exist, p;
  const int mid(l + r >> 1);
  p->lson = merge(a->lson, b->lson, l, mid);
  p->rson = merge(a->rson, b->rson, mid + 1, r);
  p->pushup();
  return p;
}
}  // namespace Segment_Tree
using namespace Segment_Tree;
namespace Suffix_Automaton {
struct node {
  int len;
  bool vis;
  tree *root;
  vector<node *> son;
  static node *null;
  node *trans[26], *fa;
  void *operator new(size_t size);
  inline node() : len(0), vis(0) {
    static bool init(0);
    if (!init) {
      init = 1;
      null = new node;
      for (int i(0); i < 26; i++) null->trans[i] = null;
      null->fa = null;
    }
    root = new tree;
    for (int i(0); i < 26; i++) trans[i] = null;
    fa = null;
  }
  inline const void travel() {
    vis = 1;
    if (fa != null) fa->son.push_back(this);
    for (int i(0); i < 26; i++)
      if (trans[i] != null && !trans[i]->vis) trans[i]->travel();
  }
  inline const void dfs() {
    for (vector<node *>::iterator i(son.begin()); i != son.end(); i++)
      (*i)->dfs(), root = merge(root, (*i)->root, 1, n);
  }
  inline const bool exist(const int &len, const int &l, const int &r) {
    if (this == null) return 0;
    return query(root, 1, n, l + len - 1, r);
  }
} * last, *root, *node::null;
char memory_pool[maxn * sizeof(node)], *tail(memory_pool + sizeof memory_pool);
inline void *node::operator new(size_t size) { return tail -= size; }
inline const void init() { last = root = new node; }
inline const void extend(const char &c, const int &k) {
  node *np(new node), *p(last);
  (last = np)->len = p->len + 1;
  insert(np->root, 1, n, k);
  for (; p != node::null && p->trans[c] == node::null; p = p->fa)
    p->trans[c] = np;
  if (p == node::null) return np->fa = root, void();
  node *q(p->trans[c]);
  if (q->len == p->len + 1) return np->fa = q, void();
  node *nq(new node);
  nq->len = p->len + 1;
  for (int i(0); i < 26; i++) nq->trans[i] = q->trans[i];
  nq->fa = q->fa;
  np->fa = q->fa = nq;
  for (; p->trans[c] == q; p = p->fa) p->trans[c] = nq;
}
inline const void build() {
  init();
  for (int i(1); i <= n; i++) extend(s[i] - 'a', i);
  root->travel();
  root->dfs();
}
inline const void query(const int &l, const int &r) {
  const int m(strlen(t + 1));
  node *p(root);
  char o;
  int pos(0);
  for (int i(1); i <= m + 1; i++) {
    for (int j(i <= m ? t[i] - 'a' + 1 : 0); j < 26; j++)
      if (p->trans[j]->exist(i, l, r)) {
        o = j + 'a';
        pos = i;
        break;
      }
    if (i <= m && p->trans[t[i] - 'a']->exist(i, l, r))
      p = p->trans[t[i] - 'a'];
    else
      break;
  }
  if (!pos) return puts("-1"), void();
  for (int i(1); i < pos; i++) putchar(t[i]);
  putchar(o);
  putchar('\n');
}
}  // namespace Suffix_Automaton
using namespace Suffix_Automaton;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  build();
  scanf("%d", &q);
  for (int l, r; q--;) scanf("%d%d", &l, &r), scanf("%s", t + 1), query(l, r);
  return 0;
}
