#include <bits/stdc++.h>
using namespace std;
namespace whatever {
int readu() {
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  int value = ch - '0';
  ch = getchar();
  while (isdigit(ch)) {
    value = value * 10 + ch - '0';
    ch = getchar();
  }
  return value;
}
void init_suffix(char *str, int n, int *suffix, int *rank, int *lcp) {
  ++n;
  for (int i = 0; i < n; ++i) rank[i] = int(str[i]);
  for (int s = 1; s < n; s *= 2) {
    int size = max(128, n);
    static int cnt[100000 + 1];
    static int temp[100000 + 1];
    memset(cnt, 0, sizeof(int) * size);
    for (int i = 0; i < n; ++i) ++cnt[rank[s + i]];
    for (int i = 1; i < size; ++i) cnt[i] += cnt[i - 1];
    for (int i = 0; i < n; ++i) temp[--cnt[rank[s + i]]] = i;
    memset(cnt, 0, sizeof(int) * size);
    for (int i = 0; i < n; ++i) ++cnt[rank[i]];
    for (int i = 1; i < size; ++i) cnt[i] += cnt[i - 1];
    for (int i = n - 1; i != -1; --i) suffix[--cnt[rank[temp[i]]]] = temp[i];
    assert(suffix[0] == n - 1);
    temp[n - 1] = 0;
    for (int i = 1; i < n; ++i)
      temp[suffix[i]] = temp[suffix[i - 1]] +
                        int(rank[suffix[i]] != rank[suffix[i - 1]] ||
                            rank[suffix[i] + s] != rank[suffix[i - 1] + s]);
    memcpy(rank, temp, sizeof(int) * n);
  }
  int cur = 0;
  for (int i = 0; str[i] != '\0'; ++i) {
    if (cur != 0) --cur;
    int prev = suffix[rank[i] - 1];
    while (str[prev + cur] == str[i + cur]) ++cur;
    lcp[rank[i] - 1] = cur;
  }
}
uint8_t log_table[100000 + 1];
int st[17][100000];
void init_st(int *lcp, int n) {
  log_table[1] = 0;
  for (int i = 2; i <= n; ++i)
    log_table[i] = log_table[i - 1] + int((i & (i - 1)) == 0);
  memcpy(st[0], lcp, sizeof(int) * n);
  for (int l = 1; l < 17; ++l)
    for (int i = (1 << l); i <= n; ++i)
      st[l][i - (1 << l)] =
          min(st[l - 1][i - (1 << l)], st[l - 1][i - (1 << (l - 1))]);
}
int query(int a, int b) {
  assert(a != b);
  if (a > b) swap(a, b);
  int l = log_table[b - a];
  return min(st[l][a], st[l][b - (1 << l)]);
}
struct node_type {
  node_type *left;
  node_type *right;
  int min;
};
const int s = (1 << 17);
node_type node[18 * (100000 + 1) + 1];
int node_cnt;
node_type *allocate() { return &node[node_cnt++]; }
node_type *nil = allocate();
node_type *insert(node_type *prev, int index, int value) {
  node_type *root = allocate();
  node_type *cur = root;
  for (int bit = (s >> 1); bit != 0; bit >>= 1) {
    assert(value < prev->min);
    cur->min = value;
    if (index & bit) {
      cur->left = prev->left;
      cur = cur->right = allocate();
      prev = prev->right;
    } else {
      cur->right = prev->right;
      cur = cur->left = allocate();
      prev = prev->left;
    }
  }
  assert(value < prev->min);
  cur->min = value;
  return root;
}
int suffix_query(node_type *cur, int index, int bit) {
  int result = INT_MAX;
  for (; bit != 0; bit >>= 1)
    if (index & bit)
      cur = cur->right;
    else {
      result = min(result, cur->right->min);
      cur = cur->left;
    }
  result = min(result, cur->min);
  return result;
}
int prefix_query(node_type *cur, int index, int bit) {
  int result = INT_MAX;
  for (; bit != 0; bit >>= 1)
    if (index & bit) {
      result = min(result, cur->left->min);
      cur = cur->right;
    } else
      cur = cur->left;
  result = min(result, cur->min);
  return result;
}
int range_query(node_type *cur, int first, int last) {
  assert(first <= last);
  for (int bit = (s >> 1); bit != 0; bit >>= 1)
    if (first & bit)
      cur = cur->right;
    else if (!(last & bit))
      cur = cur->left;
    else
      return min(suffix_query(cur->left, first, (bit >> 1)),
                 prefix_query(cur->right, last, (bit >> 1)));
  return cur->min;
}
void run() {
  nil->left = nil->right = nil;
  nil->min = INT_MAX;
  static char s[100000 + 1];
  gets(s);
  int n = int(strlen(s));
  static int suffix[100000 + 1];
  static int rank[100000 + 1 + (1 << 16)];
  static int lcp[100000];
  init_suffix(s, n, suffix, rank, lcp);
  init_st(lcp, n);
  node_type *cur = nil;
  static node_type *root[100001];
  for (int i = n; i != -1; --i) root[i] = cur = insert(cur, suffix[i], i);
  int q = readu();
  while (--q != -1) {
    int l = readu() - 1;
    int r = readu() - 1;
    static char x[200000 + 1];
    gets(x);
    int m = int(strlen(x));
    x[m] = char(1);
    int left = 0;
    int right = n + 1;
    int prev = 0;
    int length = 0;
    while (left + 1 != right) {
      int mid = (left + right) / 2;
      if (query(prev, mid) < length) {
        if (prev < mid)
          right = mid;
        else
          left = mid;
      } else {
        prev = mid;
        while (s[suffix[mid] + length] == x[length]) ++length;
        if (s[suffix[mid] + length] < x[length])
          left = mid;
        else
          right = mid;
      }
    }
    int result = n + 1;
    if (right != n + 1) {
      if (prev == left) {
        length = min(length, lcp[left]);
        while (s[suffix[right] + length] == x[length]) ++length;
        assert(s[suffix[right] + length] > x[length]);
      }
      if (l <= r - m) result = min(result, range_query(root[right], l, r - m));
      for (int i = max(l, r - m + 1); i <= r; ++i)
        if (rank[i] >= right &&
            min((rank[i] == right ? INT_MAX : query(right, rank[i])), length) <
                r - i + 1)
          result = min(result, rank[i]);
    }
    if (result != n + 1) {
      length =
          min((result == right ? INT_MAX : query(right, result)), length) + 1;
      for (int i = 0; i < length; ++i) putchar(s[suffix[result] + i]);
      putchar('\n');
    } else
      puts("-1");
  }
}
}  // namespace whatever
int main() { whatever::run(); }
