Problem: Some programming website is establishing a secure communication protocol. For security reasons, they want to choose several more or less random strings.

Initially, they have a string s consisting of lowercase English letters. Now they want to choose q strings using the following steps, and you are to help them.

  1. A string x consisting of lowercase English letters and integers l and r (1 ≤ l ≤ r ≤ |s|) are chosen. 
  2. Consider all non-empty distinct substrings of the s_l s_{l + 1} … s_r, that is all distinct strings s_i s_{i+1} … s_{j} where l ≤ i ≤ j ≤ r. Among all of them choose all strings that are lexicographically greater than x. 
  3. If there are no such strings, you should print -1. Otherwise print the lexicographically smallest among them. 



String a is lexicographically less than string b, if either a is a prefix of b and a ≠ b, or there exists such a position i (1 ≤ i ≤ min(|a|, |b|)), such that a_i < b_i and for all j (1 ≤ j < i) a_j = b_j. Here |a| denotes the length of the string a.

Input

The first line of input contains a non-empty string s (1 ≤ |s| ≤ 10^{5}) consisting of lowercase English letters.

The second line contains an integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of strings to select.

Each of the next q lines contains two integers l, r (1 ≤ l ≤ r ≤ |s|) and a non-empty string x consisting of lowercase English letters. The total length of strings x for all queries does not exceed 2 ⋅ 10^{5}.

Output

Output q lines, each of them should contain the desired string or -1, if there is no such string.

Examples

Input

baa
5
1 2 ba
2 3 a
1 2 b
2 3 aa
1 3 b


Output

-1
aa
ba
-1
ba


Input

bacb
4
1 2 ba
2 3 ac
1 3 ac
3 4 c


Output

-1
c
b
cb


Input

bba
1
1 1 b


Output

-1

Note

Consider the first example.

The string s is "baa". The queries are as follows.

  1. We consider the substring s_1 s_2 that is "ba". It has substrings "b", "a" and "ba", since none of them is greater than the query string "ba", the answer is -1.
  2. We consider substring "aa". Among its substrings only "aa" is greater than the query string "a". So the answer is "aa".
  3. We consider substring "ba". Out of "b", "a" and "ba" only "ba" is greater than the query string "b", so the answer is "ba".
  4. We consider substring "aa". No substring of "aa" is greater than the query string "aa" so the answer is -1.
  5. We consider substring "baa" and it has (among others) substrings "ba", "baa" which are greater than the query string "b". Since "ba" is lexicographically smaller than "baa", the answer is "ba". 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
struct node {
  node *c[2];
  int Min;
  node() : Min(oo) { memset(c, 0, sizeof c); }
  void update() {
    Min = oo;
    for (int i = (0), i_end_ = (2); i < i_end_; ++i) chkmin(Min, c[i]->Min);
  }
};
const int max1 = 100000;
node *nd_pool;
int nd_res = 0;
inline node *newnode() {
  if (!nd_res) nd_pool = new node[max1], nd_res = max1;
  return nd_pool + (--nd_res);
}
void build(node *&rt, int l, int r) {
  rt = newnode();
  if (r - l <= 1) return;
  int mid = (l + r) >> 1;
  build(rt->c[0], l, mid);
  build(rt->c[1], mid, r);
}
int seg_x, seg_y, seg_z, seg_ret;
void add(node *rt, int l, int r) {
  if (r - l <= 1) {
    chkmin(rt->Min, seg_z);
    return;
  }
  int mid = (l + r) >> 1;
  if (seg_x < mid)
    add(rt->c[0], l, mid);
  else
    add(rt->c[1], mid, r);
  rt->update();
}
void query(node *rt, int l, int r) {
  if (rt->Min > seg_z) return;
  if (r - l <= 1) {
    seg_ret = l;
    return;
  }
  int mid = (l + r) >> 1;
  if (seg_x < mid) query(rt->c[0], l, mid);
  if (!~seg_ret && seg_y > mid) query(rt->c[1], mid, r);
}
node *rt;
const int maxn = 500500;
const int maxqn = 200200;
inline void sortx(int *a, int *b, int *c, const int &n, const int &m) {
  static int sum[maxn + 5];
  memset(sum, 0, sizeof(int) * (m + 1));
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) ++sum[b[i]];
  for (int i = (0), i_end_ = (m); i < i_end_; ++i) sum[i + 1] += sum[i];
  for (int i = n - 1; i >= 0; --i) a[--sum[b[c[i]]]] = c[i];
}
inline void make_sa(char *s, int *sa, int *rk, const int &n) {
  static int first[maxn + 5], second[maxn + 5];
  for (int i = (0), i_end_ = (n); i < i_end_; ++i)
    first[i] = s[i], second[i] = i;
  sortx(sa, first, second, n, CHAR_MAX);
  rk[sa[0]] = 0;
  for (int i = (0), i_end_ = (n - 1); i < i_end_; ++i)
    rk[sa[i + 1]] = rk[sa[i]] + (s[sa[i]] != s[sa[i + 1]]);
  for (int i = 1; rk[sa[n - 1]] < n - 1; i <<= 1) {
    for (int j = (0), j_end_ = (n); j < j_end_; ++j)
      first[j] = j + i >= n ? 0 : rk[j + i] + 1;
    sortx(second, first, sa, n, n);
    sortx(sa, rk, second, n, n);
    memcpy(second, rk, sizeof(int) * n);
    rk[sa[0]] = 0;
    for (int j = (0), j_end_ = (n - 1); j < j_end_; ++j)
      rk[sa[j + 1]] = rk[sa[j]] + (second[sa[j]] != second[sa[j + 1]] ||
                                   first[sa[j]] != first[sa[j + 1]]);
  }
}
inline void get_height(char *s, int *h, int *sa, int *rk, const int &n) {
  int j = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    if (rk[i] + 1 >= n) continue;
    while (s[sa[rk[i]] + j] == s[sa[rk[i] + 1] + j]) ++j;
    h[rk[i]] = j;
    if (j) --j;
  }
}
int sa[maxn + 5], rk[maxn + 5], h[maxn + 5];
struct que {
  int id, l, r, pos, len;
  que() {}
  que(int _id, int _l, int _r, int _pos, int _len)
      : id(_id), l(_l), r(_r), pos(_pos), len(_len) {}
};
int n, qn;
char s[maxn + 5];
vector<que> all[maxn + 5];
const int max0 = 20;
int Min[max0][maxn + 5];
pair<int, int> ans[maxqn + 5];
int main() {
  scanf("%s", s);
  n = strlen(s);
  int ori_n = n;
  s[n++] = '#';
  scanf("%d", &qn);
  for (int i = (0), i_end_ = (qn); i < i_end_; ++i) {
    int l, r;
    static char ss[maxn + 5];
    scanf("%d%d", &l, &r), --l;
    scanf("%ss", ss);
    int len = strlen(ss);
    all[l].push_back(que(i, l, r, n, len));
    for (int j = (0), j_end_ = (len); j < j_end_; ++j) s[n++] = ss[j];
    s[n++] = '#';
  }
  s[n] = 0;
  make_sa(s, sa, rk, n);
  get_height(s, h, sa, rk, n);
  h[n - 1] = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) Min[0][i] = h[i];
  for (int i = (1), i_end_ = (max0); i < i_end_; ++i)
    for (int j = (0), j_end_ = (n); j < j_end_; ++j)
      if (j + (1 << (i - 1)) >= n)
        Min[i][j] = Min[i - 1][j];
      else
        Min[i][j] = min(Min[i - 1][j], Min[i - 1][j + (1 << (i - 1))]);
  for (int i = (0), i_end_ = (qn); i < i_end_; ++i) ans[i] = make_pair(oo, oo);
  build(rt, 0, n);
  for (int i = ori_n - 1; i >= 0; --i) {
    seg_x = rk[i], seg_z = i;
    add(rt, 0, n);
    for (auto q : all[i]) {
      for (int k = (0), k_end_ = (q.len + 1); k < k_end_; ++k) {
        int fir = rk[q.pos];
        for (int l = max0 - 1; l >= 0; --l)
          if (Min[l][fir] > k) {
            fir += 1 << l;
          }
        ++fir;
        seg_ret = -1;
        seg_x = fir, seg_y = n, seg_z = q.r - k - 1;
        if (seg_x < seg_y) query(rt, 0, n);
        if (~seg_ret) {
          chkmin(ans[q.id], make_pair(seg_ret, k + 1));
        }
      }
    }
  }
  for (int i = (0), i_end_ = (qn); i < i_end_; ++i) {
    if (ans[i].first >= oo)
      printf("-1\n");
    else {
      for (int j = (sa[ans[i].first]),
               j_end_ = (sa[ans[i].first] + ans[i].second);
           j < j_end_; ++j)
        printf("%c", s[j]);
      printf("\n");
    }
  }
  return 0;
}