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 JAVA):

Solution:
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;

import static java.lang.Math.min;

public class Test {

  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  int D = 17;
  int n;
  int N = 1 << D;
  String s, t;
  char[] cs;
  int[] ord = new int[N + N];
  int[] buf = new int[N + N];
  int[] sa = new int[N];
  int[] ra = new int[N];
  int[][] sh = new int[D][N + N];
  Integer[] idx = new Integer[N];
  int[][] H = new int[D][N];
  int[][] S = new int[D][N];
  int[][] R = new int[D][N];
  int[][][] M = new int[D][D][N];
  int[][][] P = new int[D][D][N];
  int[] ans = {-1, -1};
  int glb = -1;

  static int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static String readLine() {
    StringBuilder b = new StringBuilder();
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          b.append((char) c);
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return b.toString();
  }

  public static void main(String[] args) {
    Test te = new Test();
    te.start();
    writer.flush();
  }

  void buildSA() {
    for (int i = 0; i < n; i++) {
      idx[i] = i;
      ord[i] = s.charAt(i);
    }
    for (int i = 1; i < n; i *= 2) {
      final int len = i;
      Arrays.sort(
          idx,
          0,
          n,
          (a, b) ->
              ord[a] != ord[b]
                  ? Integer.compare(ord[a], ord[b])
                  : ord[a + len] != ord[b + len]
                      ? Integer.compare(ord[a + len], ord[b + len])
                      : Integer.compare(a, b));
      buf[idx[0]] = 1;
      for (int j = 1; j < n; j++) {
        int a = idx[j], b = idx[j - 1];
        if (ord[a] == ord[b] && ord[a + len] == ord[b + len]) buf[a] = buf[b];
        else buf[a] = buf[b] + 1;
      }
      int[] tmp = buf;
      buf = ord;
      ord = tmp;
    }
    Arrays.fill(sa, -1);
    Arrays.fill(ra, -1);
    for (int i = 0; i < n; i++) {
      sa[i] = idx[i];
      ra[sa[i]] = i;
    }
  }

  void buildST(int d, int ll, int rr) {
    if (ll >= rr) return;
    int mid = (ll + rr) / 2;
    buildST(d + 1, ll, mid);
    buildST(d + 1, mid + 1, rr);
    buildSTN(d, ll, rr);
  }

  void buildH() {
    Arrays.fill(sh[0], n);
    int l = 0;
    for (int i = 0; i < n; i++) {
      int j = ra[i];
      if (j == 0) {
        sh[0][0] = 0;
        l = 0;
        continue;
      }
      int k = sa[j - 1];
      while (i + l < n && k + l < n && cs[i + l] == cs[k + l]) l++;
      sh[0][j] = l;
      if (l > 0) l--;
    }
    for (int d = 1, b = 1; d < D; d++, b *= 2)
      for (int i = 0; i < n; i++) sh[d][i] = min(sh[d - 1][i], sh[d - 1][i + b]);
  }

  int getH(int i, int j) {
    i++;
    int ans = n;
    for (int d = D - 1, b = 1 << d; d >= 0; d--, b >>= 1)
      if (i + b - 1 <= j) {
        ans = min(ans, sh[d][i]);
        i += b;
      }
    return ans;
  }

  void buildSTN(int d, int ll, int rr) {
    for (int i = ll; i <= rr; i++) idx[i] = i;
    Arrays.sort(idx, ll, rr + 1, Comparator.comparingInt(i -> ra[i]));
    for (int i = ll; i <= rr; i++) {
      S[d][i] = idx[i];
      R[d][idx[i]] = i;
    }
    H[d][ll] = 0;
    for (int i = ll + 1; i <= rr; i++) {
      int ri = ra[S[d][i]], rj = ra[S[d][i - 1]];
      H[d][i] = getH(rj, ri);
    }
    for (int i = ll; i <= rr; i++) {
      M[d][0][i] = S[d][i];
      P[d][0][i] = H[d][i];
    }
    for (int k = 1, b = 1; b+b <= rr - ll + 1; k++, b <<= 1)
      for (int j = ll; j <= rr; j++) {
        M[d][k][j] = min(M[d][k - 1][j], j + b <= rr ? M[d][k - 1][j + b] : rr);
        P[d][k][j] = min(P[d][k - 1][j], j + b <= rr ? P[d][k - 1][j + b] : n);
      }
  }

  int getLCP(int i) {
    int j = 0;
    for (; i < n && j < t.length(); i++, j++) if (cs[i] != t.charAt(j)) break;
    return j;
  }

  void getMin(int i, int j) {
    if (ans[0] == -1 || ra[i] < ra[ans[0]]) {
      ans[0] = i;
      ans[1] = j;
    }
  }

  int getStart(int[][][] a, int d, int ll, int rr, int h) {
    for (int k = D - 1, b = 1 << k; k >= 0; k--, b >>= 1)
      if (ll + b - 1 <= rr && a[d][k][ll] >= h) ll += b;
    return ll;
  }

  void getGLB(int d, int ll, int rr, int b) {
    int i = ll - 1, j = rr + 1;
    while (j - i > 1) {
      int m = (i + j) / 2;
      if (ra[S[d][m]] > glb) j = m;
      else i = m;
    }
    if (j > rr) return;
    int start = j;
    i = S[d][start];
    int lcp = getLCP(i);
    if (i + lcp <= b) {
      getMin(i, i + lcp);
      return;
    }
    start++;
    while (start <= rr) {
      lcp = min(lcp, H[d][start]);
      ll = getStart(P, d, start, rr, lcp);
      j = getStart(M, d, start, ll - 1, b - lcp + 1);
      if (j <= ll - 1) {
        int r = S[d][j];
        getMin(r, r + lcp);
        return;
      }
      start = ll;
    }
  }

  void search(int d, int ll, int rr, int i, int j) {
    if (i > rr || j < ll) return;
    if (i <= ll && rr <= j) {
      if (ll == rr) {
        if (ra[ll] <= glb) return;
        int lcp = getLCP(ll);
        if (ll + lcp <= j) getMin(ll, ll + lcp);
        return;
      }
      getGLB(d, ll, rr, j);
      return;
    }
    int mid = (ll + rr) / 2;
    search(d + 1, ll, mid, i, j);
    search(d + 1, mid + 1, rr, i, j);
  }

  int compare(int i) {
    int j;
    for (j = 0; i < n && j < t.length(); i++, j++)
      if (cs[i] < t.charAt(j)) return -1;
      else if (cs[i] > t.charAt(j)) return 1;
    return i < n ? 1 : j < t.length() ? -1 : 0;
  }

  int getGLB() {
    int ll = -1, rr = n;
    while (rr - ll > 1) {
      int m = (rr + ll) / 2;
      if (compare(sa[m]) <= 0) ll = m;
      else rr = m;
    }
    return ll;
  }

  void start() {
    s = readLine();
    n = s.length();
    cs = s.toCharArray();
    buildSA();
    buildH();
    buildST(0, 0, n - 1);
    idx = null;
    buf = null;
    sh = null;
    int q = readInt();
    for (int i = 0; i < q; i++) {
      int ll = readInt(), rr = readInt();
      ll--;
      rr--;
      t = readLine();
      ans[0] = -1;
      ans[1] = -1;
      glb = getGLB();
      if (glb + 1 >= n) {
        writer.println(-1);
        continue;
      }
      search(0, 0, n - 1, ll, rr);
      if (ans[0] == -1) writer.println("-1");
      else writer.println(s.substring(ans[0], ans[1] + 1));
      writer.flush();
    }
  }
}