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 static java.lang.Math.min;

public class Test {

  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  int D = 17;
  int n, tn;
  int N = 1 << D;
  char[] s = new char[N], t = new char[N + N];
  int[] sa = new int[N];
  int[] ra = new int[N];
  int[][] RH = new int[D][N];
  int[][] ST = new int[D][N];

  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 readString() {
    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();
  }

  static int readChars(char[] a) {
    int cnt = 0;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          a[cnt++] = (char) c;
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return cnt;
  }

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

  void buildSA() {
    int sz = Integer.highestOneBit(n) << 1;
    int[] ord = new int[sz + sz];
    int[] buf = new int[sz + sz];
    Integer[] idx = new Integer[n];
    for (int i = 0; i < n; i++) {
      idx[i] = i;
      ord[i] = s[i];
    }
    for (int i = 1; i < n; i *= 2) {
      final int len = i;
      final int[] od = ord;
      Arrays.sort(
          idx,
          0,
          n,
          (a, b) ->
              od[a] != od[b]
                  ? Integer.compare(od[a], od[b])
                  : od[a + len] != od[b + len]
                      ? Integer.compare(od[a + len], od[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[] c = new int[n];
    for (int d = 0, b = N; b > 1; d++, b >>= 1) {
      for (int i = 0; i < n; i += b) c[i] = 0;
      for (int i = 0; i < n; i++) {
        int j = ra[i] / b * b;
        ST[d][j + c[j]++] = i;
      }
    }
  }

  void buildRH() {
    int l = 0;
    for (int i = 0; i < n; i++) {
      int j = ra[i];
      if (j == 0) {
        RH[0][0] = 0;
        l = 0;
        continue;
      }
      int k = sa[j - 1];
      while (i + l < n && k + l < n && s[i + l] == s[k + l]) l++;
      RH[0][j] = l;
      if (l > 0) l--;
    }
    buildRM(RH, 0, n - 1, n);
  }

  void buildRM(int[][] r, int ll, int rr, int max) {
    for (int d = 1, b = 1; b + b <= rr - ll + 1; d++, b <<= 1)
      for (int i = ll; i <= rr; i++)
        r[d][i] = min(r[d - 1][i], i + b <= rr ? r[d - 1][i + b] : max);
  }

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

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

  int findSTFirst(int d, int ll, int rr, int i, int j, int a, int b) {
    if (i > rr || j < ll) return -1;
    if (i <= ll && rr <= j) {
      if (ll == rr) {
        if (sa[ll] < a || sa[ll] > b) return -1;
        return ll;
      }
      int x = ll - 1, y = rr + 1;
      while (y - x > 1) {
        int m = (y + x) / 2;
        if (ST[d][m] >= a) y = m;
        else x = m;
      }
      if (y > rr || ST[d][y] > b) return -1;
    }
    int mid = (ll + rr) / 2;
    int v = findSTFirst(d + 1, ll, mid, i, j, a, b);
    return v == -1 ? findSTFirst(d + 1, mid + 1, rr, i, j, a, b) : v;
  }

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

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

  void start() {
    n = readChars(s);
    buildSA();
    buildRH();
    buildST();
    int q = readInt();
    loop:
    while (q-- > 0) {
      int ll = readInt(), rr = readInt();
      ll--;
      rr--;
      tn = readChars(t);
      int start = getLUB();
      if (start >= n) {
        writer.println(-1);
        continue;
      }
      int lcp = getLCP(sa[start]);
      while (start < n) {
        int next = getRMFirst(RH, start+1, n - 1, lcp - 1);
        int ans = findSTFirst(0, 0, N - 1, start, next - 1, ll, rr - lcp);
        if (ans != -1) {
          writer.println(new String(s, sa[ans], lcp + 1));
          continue loop;
        }
        start = next;
        lcp = min(lcp, RH[0][start]);
      }
      writer.println("-1");
    }
  }
}