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;
int n, m, num[100100];
char s[100100];
int cnt = 1;
struct Suffix_Automaton {
  int ch[26], len, fa;
} t[200100];
int Add(int x, int c) {
  int xx = ++cnt;
  t[xx].len = t[x].len + 1;
  for (; x && !t[x].ch[c]; x = t[x].fa) t[x].ch[c] = xx;
  if (!x) {
    t[xx].fa = 1;
    return xx;
  }
  int y = t[x].ch[c];
  if (t[y].len == t[x].len + 1) {
    t[xx].fa = y;
    return xx;
  }
  int yy = ++cnt;
  t[yy] = t[y], t[yy].len = t[x].len + 1;
  t[xx].fa = t[y].fa = yy;
  for (; x && t[x].ch[c] == y; x = t[x].fa) t[x].ch[c] = yy;
  return xx;
}
int dfn[200100], rev[200100], sz[200100], tot;
vector<int> v[200100];
void dfs(int x) {
  dfn[x] = ++tot, rev[tot] = x, sz[x] = 1;
  for (auto y : v[x]) dfs(y), sz[x] += sz[y];
}
int mx[800100];
void pushup(int x) { mx[x] = max(mx[x << 1], mx[x << 1 | 1]); }
void modify(int x, int l, int r, int P, int val) {
  if (l > P || r < P) return;
  if (l == r) {
    mx[x] = val;
    return;
  }
  modify(x << 1, l, ((l + r) >> 1), P, val),
      modify(x << 1 | 1, ((l + r) >> 1) + 1, r, P, val), pushup(x);
}
int query(int x, int l, int r, int L, int R) {
  if (l > R || r < L) return -1;
  if (L <= l && r <= R) return mx[x];
  return max(query(x << 1, l, ((l + r) >> 1), L, R),
             query(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R));
}
int L[200100], R[200100], len[200100], ord[200100], res[200100];
char ss[200100], *q[200100];
bool func(int id, int pos, int x) {
  if (pos < len[id] && t[x].ch[q[id][pos] - 'a'] &&
      func(id, pos + 1, t[x].ch[q[id][pos] - 'a']))
    return true;
  for (int i = (pos < len[id] ? q[id][pos] - 'a' + 1 : 0), y; i < 26; i++)
    if ((y = t[x].ch[i]) &&
        (res[id] = query(1, 1, tot, dfn[y], dfn[y] + sz[y] - 1) - pos) >= L[id])
      return true;
  return false;
}
int main() {
  scanf("%s%d", s, &m), n = strlen(s);
  for (int i = 0, las = 1; i < n; i++) num[i] = las = Add(las, s[i] - 'a');
  for (int i = 2; i <= cnt; i++) v[t[i].fa].push_back(i);
  dfs(1), memset(mx, -1, sizeof(mx));
  q[1] = ss;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%s", &L[i], &R[i], q[i]), L[i]--, R[i]--, len[i] = strlen(q[i]);
    q[i + 1] = q[i] + len[i];
    ord[i] = i;
  }
  sort(ord + 1, ord + m + 1, [](int x, int y) { return R[x] < R[y]; });
  for (int i = 0, j = 1; i < n; i++) {
    modify(1, 1, tot, dfn[num[i]], i);
    for (; j <= m && R[ord[j]] == i; j++) {
      if (!func(ord[j], 0, 1)) res[ord[j]] = -1;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (res[i] == -1) {
      puts("-1");
      continue;
    }
    for (int j = 0; j <= len[i]; j++) {
      printf("%c", s[res[i] + j]);
      if (s[res[i] + j] != q[i][j]) break;
    }
    puts("");
  }
  return 0;
}