#include <bits/stdc++.h>
namespace IO {
template <typename T>
inline void swap(T &x, T &y) {
  T tmp = x;
  x = y, y = tmp;
}
template <typename T>
inline T abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
inline T min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
inline T max(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
}  // namespace IO
using namespace IO;
const int MAXN = 2e5;
int N, Q;
char str[MAXN + 7];
struct Smt {
  struct Node {
    Node *left, *right;
    Node() : left(NULL), right(NULL) {}
  } * root[MAXN * 2 + 7];
  void insert(int L, int l, int r, Node *&now) {
    now = new Node();
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (L <= mid)
      insert(L, l, mid, now->left);
    else
      insert(L, mid + 1, r, now->right);
  }
  Node *merge(Node *a, Node *b) {
    if (a == NULL) return b;
    if (b == NULL) return a;
    Node *now = new Node();
    now->left = merge(a->left, b->left);
    now->right = merge(a->right, b->right);
    return now;
  }
  int query(int L, int R, int l, int r, Node *now) {
    if (now == NULL) return 0;
    if (L <= l && r <= R) return 1;
    int mid = (l + r) >> 1;
    if (L <= mid)
      if (query(L, R, l, mid, now->left)) return 1;
    if (mid < R)
      if (query(L, R, mid + 1, r, now->right)) return 1;
    return 0;
  }
} smt;
struct Sam {
  struct Node {
    int fa, len;
    int son[26];
  } node[MAXN * 2 + 7];
  int last = 1, cntNode = 1;
  void extend(int c) {
    int p = last, np = last = ++cntNode;
    node[np].len = node[p].len + 1;
    smt.insert(node[np].len, 1, N, smt.root[np]);
    for (; p && !node[p].son[c]; p = node[p].fa) node[p].son[c] = np;
    if (!p)
      node[np].fa = 1;
    else {
      int q = node[p].son[c];
      if (node[q].len == node[p].len + 1)
        node[np].fa = q;
      else {
        int nq = ++cntNode;
        node[nq] = node[q];
        node[nq].len = node[p].len + 1;
        for (; p && node[p].son[c] == q; p = node[p].fa) node[p].son[c] = nq;
        node[np].fa = node[q].fa = nq;
      }
    }
  }
  int cntLen[MAXN * 2 + 7], idx[MAXN * 2 + 7];
  void prepare() {
    for (int i = 1; i <= cntNode; ++i) ++cntLen[node[i].len];
    for (int i = 1; i <= cntNode; ++i) cntLen[i] += cntLen[i - 1];
    for (int i = 1; i <= cntNode; ++i) idx[cntLen[node[i].len]--] = i;
    for (int i = cntNode; i; --i)
      smt.root[node[idx[i]].fa] =
          smt.merge(smt.root[node[idx[i]].fa], smt.root[idx[i]]);
  }
  void query(int l, int r, char *str) {
    std::vector<int> vec;
    for (int i = 0, u = 1;; ++i) {
      int c = str[i] - 'a';
      int nex = -1;
      for (int j = max(c + 1, 0); j < 26; ++j)
        if (node[u].son[j] &&
            smt.query(l + i, r, 1, N, smt.root[node[u].son[j]])) {
          nex = j;
          break;
        }
      vec.push_back(nex);
      if (c < 0 || !node[u].son[c] ||
          !smt.query(l + i, r, 1, N, smt.root[node[u].son[c]]))
        break;
      u = node[u].son[c];
    }
    while (!vec.empty() && !~vec.back()) vec.pop_back();
    if (vec.empty())
      puts("-1");
    else {
      for (int i = 0, endi = vec.size() - 1; i < endi; ++i) std::cout << str[i];
      std::cout << char(vec.back() + 'a');
      puts("");
    }
  }
} sam;
void input() {
  scanf("%s", str);
  N = strlen(str);
  for (int i = 0; i < N; ++i) sam.extend(str[i] - 'a');
  sam.prepare();
}
void solve() {
  scanf("%d", &Q);
  while (Q--) {
    int l, r;
    scanf("%d %d %s", &l, &r, str);
    sam.query(l, r, str);
  }
}
void Main() {
  input();
  solve();
}
int main() {
  Main();
  return 0;
}
