#include <bits/stdc++.h>
using std::make_pair;
template <typename T>
inline T read() {
  T x = 0;
  char ch = std::getchar();
  bool f = 0;
  while (!std::isdigit(ch)) {
    f = (ch == '-');
    ch = std::getchar();
  }
  while (std::isdigit(ch)) {
    x = x * 10 + (ch - '0');
    ch = std::getchar();
  }
  return f ? -x : x;
}
template <typename T>
void print(T x) {
  if (x < 0) {
    x = -x;
    std::putchar('-');
  }
  if (x < 10) {
    std::putchar(x + 48);
    return;
  }
  print<T>(x / 10);
  std::putchar(x % 10 + 48);
  return;
}
namespace Solution {
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::map;
using std::pair;
using std::queue;
using std::set;
using std::vector;
const int N = 204001, mod = 1e9 + 7;
char s[N], T[N];
int n, tot, lst, cnt, rt[N], ls[N * 50], rs[N * 50], nxt[N];
struct Node {
  int lnk, len;
  map<char, int> mp;
} kk[N * 2];
void insert(int &nw, int L, int R, int pos) {
  if (!nw) {
    nw = ++cnt;
  }
  if (L == R) {
    return;
  }
  int mid((L + R) / 2);
  pos <= mid ? insert(ls[nw], L, mid, pos) : insert(rs[nw], mid + 1, R, pos);
}
int merge(int x, int y, int L, int R) {
  if (!x || !y) {
    return x + y;
  }
  if (L == R) {
    return x;
  }
  int mid((L + R) / 2), nw = ++cnt;
  ls[nw] = merge(ls[x], ls[y], L, mid);
  rs[nw] = merge(rs[x], rs[y], mid + 1, R);
  return nw;
}
void insert(char ch) {
  int cur = ++tot, p = lst;
  kk[cur].len = kk[p].len + 1;
  while (p && !kk[p].mp.count(ch)) {
    kk[p].mp[ch] = cur;
    p = kk[p].lnk;
  }
  if (p) {
    int q = kk[p].mp[ch];
    if (kk[q].len == kk[p].len + 1) {
      kk[cur].lnk = q;
    } else {
      int clo = ++tot;
      kk[clo] = kk[q];
      kk[clo].len = kk[p].len + 1;
      while (p && kk[p].mp[ch] == q) {
        kk[p].mp[ch] = clo;
        p = kk[p].lnk;
      }
      kk[q].lnk = kk[cur].lnk = clo;
    }
  } else {
    kk[cur].lnk = 1;
  }
  insert(rt[lst = cur], 1, n, kk[cur].len);
}
std::vector<int> v[N];
bool query(int ql, int qr, int L, int R, int nw) {
  if (!nw) {
    return 0;
  }
  if (ql <= L && R <= qr) {
    return 1;
  }
  if (qr < ql) {
    return 0;
  }
  int mid((L + R) / 2);
  if (ql <= mid && mid < qr) {
    return query(ql, qr, L, mid, ls[nw]) | query(ql, qr, mid + 1, R, rs[nw]);
  } else if (ql <= mid) {
    return query(ql, qr, L, mid, ls[nw]);
  } else {
    return query(ql, qr, mid + 1, R, rs[nw]);
  }
}
void dfs(int u) {
  for (int i : v[u]) {
    dfs(i);
    rt[u] = merge(rt[u], rt[i], 1, n);
  }
}
void Fakemain() {
  lst = tot = 1;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i(1); i <= n; ++i) {
    insert(s[i]);
  }
  for (int i(2); i <= tot; ++i) {
    v[kk[i].lnk].push_back(i);
  }
  dfs(1);
  int m;
  scanf("%d", &m);
  while (m--) {
    int l, r, x(1);
    scanf("%d %d %s", &l, &r, T + 1);
    int len = strlen(T + 1);
    int i;
    for (i = 1; i <= len + 1; ++i) {
      nxt[i] = -1;
      for (int j(std::max(0, T[i] - 'a' + 1)), y; j < 26; ++j) {
        y = kk[x].mp[j + 'a'];
        if (y && query(l + i - 1, r, 1, n, rt[y])) {
          nxt[i] = j;
          break;
        }
      }
      x = kk[x].mp[T[i]];
      if (!x || !query(l + i - 1, r, 1, n, rt[x]) || i == len + 1) {
        break;
      }
    }
    while (i && nxt[i] == -1) {
      --i;
    }
    if (!i) {
      puts("-1");
    } else {
      for (int j(1); j < i; ++j) {
        putchar(T[j]);
      }
      putchar(nxt[i] + 'a');
      putchar('\n');
    }
  }
  return;
}
}  // namespace Solution
int main(int argc, char *argv[]) {
  Solution::Fakemain();
  return 0;
}
