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;
const int N = 5e5 + 10, INF = 66666666;
int n, Q;
int beg[N], Log[N], len[N], le[N], ri[N], ord[N], a[N], ans[N][2];
char s[N], t[N];
namespace SA {
int rk[N], height[N], h[N][20];
int wa[N], wb[N], wx[N], wy[N], sa[N];
bool cmp(int *r, int a, int b, int l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
void getsa(int *r, int n, int m) {
  int *x = wa, *y = wb, *t, i, j, p;
  for (i = 0; i < m; ++i) wx[i] = 0;
  for (i = 0; i < n; ++i) wx[x[i] = r[i]]++;
  for (i = 1; i < m; ++i) wx[i] += wx[i - 1];
  for (i = n - 1; ~i; --i) sa[--wx[x[i]]] = i;
  for (j = 1, p = 0; p < n; j <<= 1, m = p) {
    for (p = 0, i = n - j; i < n; ++i) y[p++] = i;
    for (i = 0; i < n; ++i)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    for (i = 0; i < n; ++i) wy[i] = x[y[i]];
    for (i = 0; i < m; ++i) wx[i] = 0;
    for (i = 0; i < n; ++i) wx[wy[i]]++;
    for (i = 1; i < m; ++i) wx[i] += wx[i - 1];
    for (i = n - 1; ~i; --i) sa[--wx[wy[i]]] = y[i];
    for (t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; i < n; ++i)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
  }
}
void getheight(int *a) {
  int i, j, k = 0;
  for (i = 1; i <= n; ++i) rk[sa[i]] = i;
  for (i = 0; i < n; height[rk[i++]] = k)
    for (k ? k-- : 0, j = sa[rk[i] - 1]; a[i + k] == a[j + k]; k++)
      ;
  for (int i = 0; i <= n; ++i) h[i][0] = height[i];
  for (int j = 1; j < 20; ++j)
    for (int i = 1; i + (1 << j - 1) <= n; ++i)
      h[i][j] = min(h[i][j - 1], h[i + (1 << j - 1)][j - 1]);
}
int calc(int l, int r) {
  if (l == r) return h[l][0];
  int t = Log[r - l + 1];
  return min(h[l][t], h[r - (1 << t) + 1][t]);
}
int lcp(int x, int y) {
  x = rk[x];
  y = rk[y];
  if (x > y) swap(x, y);
  return calc(x + 1, y);
}
}  // namespace SA
using SA::getheight;
using SA::getsa;
using SA::h;
using SA::lcp;
using SA::rk;
using SA::sa;
namespace Segment {
int w[N << 2];
void build(int x, int l, int r) {
  w[x] = INF;
  if (l == r) return;
  int mid = (l + r >> 1);
  build((x << 1), l, mid);
  build((x << 1 | 1), mid + 1, r);
}
void update(int x, int l, int r, int p, int v) {
  if (l == r && l == p) {
    w[x] = min(w[x], v);
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    update((x << 1), l, mid, p, v);
  else
    update((x << 1 | 1), mid + 1, r, p, v);
  w[x] = min(w[(x << 1)], w[(x << 1 | 1)]);
}
int query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return w[x];
  int mid = (l + r) >> 1, ret = INF;
  if (L <= mid) ret = query((x << 1), l, mid, L, R);
  if (R > mid) ret = min(ret, query((x << 1 | 1), mid + 1, r, L, R));
  return ret;
}
};  // namespace Segment
using Segment::build;
using Segment::query;
using Segment::update;
bool cmpp(int x, int y) { return rk[beg[x]] > rk[beg[y]]; }
int main() {
  Log[0] = -1;
  for (int i = 1; i < N; ++i) Log[i] = Log[i >> 1] + 1;
  scanf("%s%d", s, &Q);
  n = strlen(s);
  s[n++] = 'a' - 1;
  for (int i = 0; i < Q; ++i) {
    scanf("%d%d%s", &le[i], &ri[i], t);
    beg[i] = n + 1;
    ord[i] = i;
    for (len[i] = 0; t[len[i]]; ++len[i]) s[n++] = t[len[i]];
    s[n++] = 'a' - 1;
  }
  for (int i = 0; i < n; ++i) a[i] = s[i] - 'a' + 2;
  a[n] = 0;
  getsa(a, n + 1, 30);
  getheight(a);
  for (int i = n; i; --i) rk[i] = rk[i - 1];
  rk[0] = 0;
  for (int i = 0; i <= n; ++i) ++sa[i];
  sort(ord, ord + Q, cmpp);
  build(1, 1, N - 10);
  for (int i = 0, las = n + 1; i < Q; ++i) {
    int j = ord[i], p = rk[beg[j]];
    if (p == n) {
      ans[j][0] = -1;
      continue;
    }
    while (las > p) --las, update(1, 1, N - 10, sa[las], las);
    int L = min(h[p + 1][0], len[j]), k;
    if (ri[j] - L >= le[j]) {
      k = query(1, 1, N - 10, le[j], ri[j] - L);
      if (k <= n) {
        ans[j][0] = sa[k];
        ans[j][1] = lcp(ans[j][0], beg[j]) + 1;
      }
    }
    for (int k = max(ri[j] - L + 1, le[j]); k <= ri[j]; ++k) {
      if (rk[k] > p) {
        int t = lcp(k, beg[j]);
        if (k + t <= ri[j]) {
          if (!ans[j][0] || rk[ans[j][0]] > rk[k])
            ans[j][0] = k, ans[j][1] = t + 1;
        }
      }
    }
    if (!ans[j][0]) ans[j][0] = -1;
  }
  for (int i = 0; i < Q; ++i) {
    if (!~ans[i][0])
      puts("-1");
    else {
      for (int j = 0; j < ans[i][1]; ++j) putchar(s[ans[i][0] + j - 1]);
      puts("");
    }
  }
  return 0;
}