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 MAXN = 2e5;
int N;
string S;
int suffarr[MAXN];
int suffval[MAXN];
vector<pair<int, int>> buckets1[MAXN];
vector<int> buckets2[MAXN];
void buildSuffixArray() {
  int V = 26;
  for (int i = 0; i < N; i++) {
    suffval[i] = S[i] - 'a';
  }
  for (int l = 1; l == 1 || l < N; l *= 2) {
    for (int i = 0; i < N; i++) {
      int v2 = (i + l >= N) ? -1 : suffval[i + l];
      assert(-1 <= v2 && v2 < V);
      buckets2[v2 + 1].push_back(i);
    }
    for (int v2 = -1; v2 < V; v2++) {
      for (int i : buckets2[v2 + 1]) {
        int v1 = suffval[i];
        assert(0 <= v1 && v1 < V);
        buckets1[v1].emplace_back(i, v2);
      }
      buckets2[v2 + 1].clear();
    }
    int NV = -1;
    pair<int, int> lastVal(-1, -1);
    for (int v1 = 0; v1 < V; v1++) {
      for (auto it : buckets1[v1]) {
        int i = it.first, v2 = it.second;
        assert(v1 == suffval[i]);
        pair<int, int> val(v1, v2);
        assert(val >= lastVal);
        if (val == lastVal) {
          assert(NV >= 0);
          suffval[i] = NV;
        } else {
          NV++;
          suffval[i] = NV;
          lastVal = val;
        }
      }
      buckets1[v1].clear();
    }
    V = NV + 1;
  }
  assert(V == N);
  for (int i = 0; i < N; i++) {
    suffarr[i] = -1;
  }
  for (int i = 0; i < N; i++) {
    assert(0 <= suffval[i] && suffval[i] < N);
    assert(suffarr[suffval[i]] == -1);
    suffarr[suffval[i]] = i;
  }
}
const int NSEG = 1 << 17;
int seg[2 * NSEG];
void segUpdate(int ind, int v) {
  for (int i = ind + NSEG; i; i /= 2) {
    assert(v < seg[i]);
    seg[i] = v;
  }
}
int segQuery(int l, int r, int v) {
  int lcnd = -1;
  int rcnd = -1;
  for (int a = l + NSEG, b = r + NSEG; a < b; a /= 2, b /= 2) {
    if (a & 1) {
      if (seg[a] <= v) {
        if (lcnd == -1) {
          lcnd = a;
        }
      }
      a++;
    }
    if (b & 1) {
      b--;
      if (seg[b] <= v) {
        rcnd = b;
      }
    }
  }
  int cur;
  if (lcnd != -1)
    cur = lcnd;
  else if (rcnd != -1)
    cur = rcnd;
  else
    return -1;
  assert(seg[cur] <= v);
  while (cur < NSEG) {
    if (seg[2 * cur] <= v) {
      cur = 2 * cur;
    } else if (seg[2 * cur + 1] <= v) {
      cur = 2 * cur + 1;
    } else
      assert(false);
  }
  return cur - NSEG;
}
const int MAXQ = 2.1e5;
int Q;
using pii = pair<int, int>;
pair<pii, string> queries[MAXQ];
string res[MAXQ];
vector<int> lQueries[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> S;
  N = int(S.size());
  buildSuffixArray();
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    int l, r;
    cin >> l >> r >> queries[q].second;
    l--, r--;
    queries[q].first = pii(l, r);
    lQueries[l].push_back(q);
  }
  for (int i = 2 * NSEG - 1; i > 0; i--) {
    seg[i] = N;
  }
  for (int l = N - 1; l >= 0; l--) {
    {
      int ind = suffval[l];
      assert(suffarr[ind] == l);
      segUpdate(ind, l);
    }
    for (int q : lQueries[l]) {
      assert(l == queries[q].first.first);
      int r = queries[q].first.second;
      string& x = queries[q].second;
      int st = 0, en = N;
      int resind = -1;
      int reslen = -1;
      for (int i = 0; i <= int(x.size()); i++, r--) {
        char c = size_t(i) < x.size() ? x[size_t(i)] : -1;
        int mi = st - 1, ma = en;
        while (ma - mi > 1) {
          int md = (mi + ma) / 2;
          char cnd = (suffarr[md] + i < N) ? S[suffarr[md] + i] : -1;
          if (cnd <= c) {
            mi = md;
          } else {
            ma = md;
          }
        }
        int nen = ma;
        mi = st - 1, ma = nen;
        while (ma - mi > 1) {
          int md = (mi + ma) / 2;
          char cnd = (suffarr[md] + i < N) ? S[suffarr[md] + i] : -1;
          if (cnd < c) {
            mi = md;
          } else {
            ma = md;
          }
        }
        int nst = ma;
        int v = segQuery(nen, en, r);
        if (v != -1) {
          resind = suffarr[v];
          reslen = i + 1;
          assert(resind + reslen <= N);
        }
        st = nst, en = nen;
      }
      if (resind == -1) {
        res[q] = "-1";
      } else {
        res[q] = S.substr(resind, reslen);
      }
    }
  }
  for (int q = 0; q < Q; q++) {
    cout << res[q] << '\n';
  }
  return 0;
}