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 = 400005;
int a[N][26], len[N], lk[N], rt[N], ch[N * 50][2], sp[N];
vector<int> v[N];
int n, m, qn, cnt, la = 0, now, inx = 0;
char c[N], s[N];
void ins(int& x, int p, int l, int r) {
  if (!x) x = ++cnt;
  if (l == r) return;
  if (p <= ((l + r) >> 1))
    ins(ch[x][0], p, l, ((l + r) >> 1));
  else
    ins(ch[x][1], p, ((l + r) >> 1) + 1, r);
}
void extend(int c) {
  int p, q;
  len[now = ++inx] = len[la] + 1;
  ins(rt[now], len[now], 1, n);
  for (p = la, la = now; p > -1 && !a[p][c]; p = lk[p]) a[p][c] = now;
  if (p == -1) {
    lk[now] = 0;
    return;
  }
  if (len[p] + 1 == len[q = a[p][c]]) {
    lk[now] = q;
    return;
  }
  ++inx;
  len[inx] = len[p] + 1;
  lk[inx] = lk[q];
  memcpy(a[inx], a[q], sizeof(a[q]));
  for (; p > -1 && a[p][c] == q; p = lk[p]) a[p][c] = inx;
  lk[now] = lk[q] = inx;
}
int merge(int x, int y, int l = 1, int r = n) {
  if (!x || !y || l == r) return x | y;
  int now = ++cnt;
  ch[now][0] = merge(ch[x][0], ch[y][0], l, ((l + r) >> 1));
  ch[now][1] = merge(ch[x][1], ch[y][1], ((l + r) >> 1) + 1, r);
  return now;
}
void dfs(int x) {
  for (int go : v[x]) dfs(go), rt[x] = merge(rt[x], rt[go]);
}
bool ck(int x, int fl, int fr, int l = 1, int r = n) {
  if (!x || r < fl || l > fr) return false;
  if (fl <= l && r <= fr) return true;
  if (ck(ch[x][0], fl, fr, l, ((l + r) >> 1))) return true;
  if (ck(ch[x][1], fl, fr, ((l + r) >> 1) + 1, r)) return true;
  return false;
}
int main() {
  scanf("%s", c + 1);
  n = strlen(c + 1);
  lk[0] = -1;
  for (int i = (1), e_ = (n); i <= e_; ++i) extend(c[i] - 'a');
  for (int i = (1), e_ = (inx); i <= e_; ++i) v[lk[i]].push_back(i);
  dfs(0);
  int k, x, l, r, ans;
  scanf("%d", &qn);
  for (int o = (1), e_ = (qn); o <= e_; ++o) {
    scanf("%d %d %s", &l, &r, c + 1);
    m = strlen(c + 1);
    x = k = sp[0] = 0;
    for (int i = (1), e_ = (m); i <= e_; ++i) {
      x = a[x][c[i] - 'a'];
      if (!x || !ck(rt[x], l + i - 1, r)) break;
      sp[i] = x;
      ++k;
    }
    ans = -1;
    for (int i = (k), e_ = (0); i >= e_; --i) {
      for (int j = (((c[i + 1] - 'a' + 1) > (0) ? (c[i + 1] - 'a' + 1) : (0))),
               e_ = (25);
           j <= e_; ++j)
        if (a[sp[i]][j] && ck(rt[a[sp[i]][j]], l + i, r)) {
          k = i;
          ans = j;
          break;
        }
      if (ans != -1) break;
    }
    if (ans < 0) {
      puts("-1");
      continue;
    }
    for (int i = (1), e_ = (k); i <= e_; ++i) putchar(c[i]);
    putchar('a' + ans);
    puts("");
  }
  return 0;
}