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;
inline int read() {
  int w = 0, x = 0;
  char c = getchar();
  while (!isdigit(c)) w |= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
  return w ? -x : x;
}
namespace star {
const int maxn = 1e6 + 10;
int n, rt[maxn];
struct SAM {
  struct node {
    int len, link, nxt[26];
    node() : len(), link(), nxt() {}
  } e[maxn];
  int lst, tot;
  SAM() : e(), lst(1), tot(1), S() { e[1].len = 0, e[1].link = -1; }
  struct SegmentTree {
    int tot, son[maxn << 2][2];
    SegmentTree() : tot(), son() {}
    void insert(const int &x, int &ro, const int l = 1, const int r = n) {
      ro = ++tot;
      if (l == r) return;
      x <= ((l + r) >> 1) ? insert(x, son[ro][0], l, ((l + r) >> 1))
                          : insert(x, son[ro][1], ((l + r) >> 1) + 1, r);
    }
    bool query(const int &x, const int &y, const int &ro, const int &l = 1,
               const int &r = n) {
      if (!ro) return false;
      if (x == l and y == r) return true;
      if (y <= ((l + r) >> 1))
        return query(x, y, son[ro][0], l, ((l + r) >> 1));
      else if (x > ((l + r) >> 1))
        return query(x, y, son[ro][1], ((l + r) >> 1) + 1, r);
      else
        return query(x, ((l + r) >> 1), son[ro][0], l, ((l + r) >> 1)) ||
               query(((l + r) >> 1) + 1, y, son[ro][1], ((l + r) >> 1) + 1, r);
    }
    int merge(const int &a, const int &b, const int &l = 1, const int &r = n) {
      if (!a or !b or l == r) return a | b;
      int ro = ++tot;
      son[ro][0] = merge(son[a][0], son[b][0], l, ((l + r) >> 1));
      son[ro][1] = merge(son[a][1], son[b][1], ((l + r) >> 1) + 1, r);
      return ro;
    }
  } S;
  void insert(int c, int pos) {
    int x = ++tot;
    e[x].len = e[lst].len + 1;
    S.insert(pos, rt[x]);
    int u = lst;
    while (u != -1 and !e[u].nxt[c]) e[u].nxt[c] = x, u = e[u].link;
    if (u == -1)
      e[x].link = 1;
    else {
      int y = e[u].nxt[c];
      if (e[u].len + 1 == e[y].len)
        e[x].link = y;
      else {
        int clone = ++tot;
        e[clone] = e[y];
        e[clone].len = e[u].len + 1;
        while (u != -1 and e[u].nxt[c] == y) e[u].nxt[c] = clone, u = e[u].link;
        e[y].link = e[x].link = clone;
      }
    }
    lst = x;
  }
} S;
vector<int> V[maxn];
void dfs(int x) {
  for (auto &&u : V[x]) dfs(u), rt[x] = S.S.merge(rt[x], rt[u]);
}
char s[maxn];
int nxt[maxn];
inline void work() {
  scanf("%s", s);
  n = strlen(s);
  for (char *c = s; *c; c++) S.insert(*c - 'a', c - s + 1);
  for (int i = 2; i <= S.tot; i++) V[S.e[i].link].push_back(i);
  dfs(1);
  int m = read();
  while (m--) {
    int l = read(), r = read();
    scanf("%s", s);
    int k = strlen(s), now = 1;
    int i;
    for (i = 0;; i++) {
      nxt[i] = -1;
      for (int j = max(s[i] - 'a' + 1, 0); j < 26; j++)
        if (S.e[now].nxt[j] and S.S.query(l + i, r, rt[S.e[now].nxt[j]])) {
          nxt[i] = j;
          break;
        }
      int x = S.e[now].nxt[s[i] - 'a'];
      if (!x or i == k or !S.S.query(l + i, r, rt[x])) break;
      now = x;
    }
    while (~i and nxt[i] == -1) i--;
    if (i == -1)
      puts("-1");
    else {
      for (int j = 0; j < i; j++) putchar(s[j]);
      putchar(nxt[i] + 'a');
      puts("");
    }
  }
}
}  // namespace star
signed main() {
  star::work();
  return 0;
}