#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma GCC optimize("Ofast,-funroll-loops,-fno-stack-protector")
#pragma GCC target( \
    "popcnt,sse,sse2,sse3,ssse3,sse4,avx,avx2,abm,mmx,tune=native")
using namespace std;
static constexpr int Maxn = 1e5 + 5;
static constexpr int Maxs = 5e5 + 1e5 + 5;
static constexpr int Maxm = 5e5 + 5;
static constexpr int LOG = 20;
int n, m, len;
string str, ttr[Maxn];
char s[Maxs];
int id[Maxs];
pair<int, int> ans[Maxm];
namespace SA {
static constexpr int Maxn = ::Maxs;
static constexpr int LOG = ::LOG;
int wa[Maxn], wb[Maxn], wc[Maxn], _s[Maxn];
int sa[Maxn], rnk[Maxn], height[Maxn];
int ST[Maxn][LOG], N;
template <typename T>
void build(T *ss, int n, int m) {
  N = n;
  register int *x = wa, *y = wb, *tmp;
  register int i, j, w;
  for (i = 1; i <= n; ++i) _s[i] = ss[i];
  for (i = 1; i <= n; ++i) x[i] = _s[i], y[i] = i;
  for (i = 1; i <= m; ++i) wc[i] = 0;
  for (i = 1; i <= n; ++i) wc[x[i]]++;
  for (i = 2; i <= m; ++i) wc[i] += wc[i - 1];
  for (i = n; i >= 1; --i) sa[wc[x[y[i]]]--] = y[i];
  for (w = 1; w <= n; w <<= 1) {
    register int tot = 0;
    for (i = n - w + 1; i <= n; ++i) y[++tot] = i;
    for (i = 1; i <= n; ++i)
      if (sa[i] > w) y[++tot] = sa[i] - w;
    for (i = 1; i <= m; ++i) wc[i] = 0;
    for (i = 1; i <= n; ++i) wc[x[i]]++;
    for (i = 2; i <= m; ++i) wc[i] += wc[i - 1];
    for (i = n; i >= 1; --i) sa[wc[x[y[i]]]--] = y[i];
    tmp = x, x = y, y = tmp, x[sa[1]] = 1, tot = 1;
    for (i = 2; i <= n; ++i)
      x[sa[i]] = ((y[sa[i]] == y[sa[i - 1]] && y[sa[i] + w] == y[sa[i - 1] + w])
                      ? tot
                      : ++tot);
    if (tot == n) break;
    m = tot;
  }
  for (i = 1; i <= n; ++i) rnk[sa[i]] = i;
  for (i = 1, w = 0; i <= n; ++i) {
    if (rnk[i] == 1) continue;
    if (w) --w;
    int j = sa[rnk[i] - 1];
    while (i + w <= n && j + w <= n && _s[i + w] == _s[j + w]) w++;
    height[rnk[i]] = w;
  }
  for (int i = 1; i <= n; ++i) ST[i][0] = height[i];
  for (int j = 1; j < LOG; ++j)
    for (int i = 1; i + (1 << j) - 1 <= n; ++i)
      ST[i][j] = min(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
}
__attribute__((__always_inline__)) __inline int get_lcp(int x1, int x2) {
  if (x1 == x2) {
    return N - x1 + 1;
  } else {
    x1 = rnk[x1], x2 = rnk[x2];
    if (x1 > x2) swap(x1, x2);
    ++x1;
    int k = 31 - __builtin_clz(x2 - x1 + 1);
    return min(ST[x1][k], ST[x2 - (1 << k) + 1][k]);
  }
}
void get_lcp_range(int x, int len, int &l, int &r) {
  x = rnk[x], l = r = x;
  int j;
  for (j = 0; l - (1 << j) + 1 >= 2; ++j)
    ;
  for (; ~--j;) {
    if (l - (1 << j) + 1 >= 2 && ST[l - (1 << j) + 1][j] >= len) {
      l -= (1 << j);
    }
  }
  for (j = 0; r + (1 << j) <= N; ++j)
    ;
  for (; ~--j;) {
    if (r + (1 << j) <= N && ST[r + 1][j] >= len) {
      r += (1 << j);
    }
  }
}
}  // namespace SA
using SA::build;
using SA::get_lcp;
using SA::get_lcp_range;
using SA::height;
using SA::rnk;
using SA::sa;
struct Query {
  int l, r, vl, vr, id, block;
  Query() { memset(this, 0, sizeof(*this)); }
  Query(int l, int r, int vl, int vr, int id)
      : l(l), r(r), vl(vl), vr(vr), id(id) {
    block = ((l - 1) / (int)sqrt(len) / 2) + 1;
  }
  friend bool operator<(const Query &c, const Query &d) {
    return (c.block ^ d.block) ? c.block < d.block
                               : ((c.block & 1) ? c.r < d.r : c.r > d.r);
  }
  ~Query() = default;
} qry[Maxm];
bool cmp(pair<int, int> x, pair<int, int> y) {
  return x.first > y.first || (x.first == y.first && x.second < y.second);
}
namespace block {
static constexpr int Maxn = ::Maxn;
static constexpr int BLOCK = 400;
int blk, bls, bl[Maxn];
int bL[BLOCK], bR[Maxn];
int cnt[Maxn], cc[BLOCK][Maxn];
int ans[BLOCK];
__attribute__((__always_inline__)) __inline void add(int x, int val) {
  int b = bl[x];
  if (val == 1) {
    cc[b][cnt[x]]--;
    ++cnt[x];
    cc[b][cnt[x]]++;
    ans[b] = max(ans[b], cnt[x]);
  } else {
    cc[b][cnt[x]]--;
    --cnt[x];
    cc[b][cnt[x]]++;
    if (!cc[b][ans[b]]) ans[b]--;
  }
}
pair<int, int> query(int l, int r) {
  int pl = bl[l], pr = bl[r];
  if (pl == pr) {
    pair<int, int> res(0, l);
    for (int i = l; i <= r; ++i) res = min(res, make_pair(cnt[i], i), cmp);
    return res;
  }
  auto res = min(query(l, bR[pl]), query(bL[pr], r), cmp);
  if (pl + 1 == pr) {
    return res;
  } else {
    pair<int, int> rres(0, pl + 1);
    for (int b = pl + 1; b < pr; ++b)
      rres = min(rres, make_pair(ans[b], b), cmp);
    if (rres.first != 0) {
      int b = rres.second;
      for (int i = bL[b]; i <= bR[b]; ++i)
        if (cnt[i] == rres.first) {
          rres.second = i;
          break;
        }
    } else {
      rres.second = bL[rres.second];
    }
    return min(res, rres, cmp);
  }
}
void init(int len) {
  blk = 350;
  for (int i = 1; i <= len; ++i) bl[i] = (i - 1) / blk + 1;
  bls = bl[len];
  for (int i = 1; i <= bls; ++i) {
    bL[i] = (i - 1) * blk + 1;
    bR[i] = i * blk;
    if (bR[i] > len) bR[i] = len;
  }
  memset(ans, 0, sizeof(ans));
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= bls; ++i) cc[i][0] = 1e7;
}
}  // namespace block
__attribute__((__always_inline__)) __inline void mo_add(int x) {
  x = sa[x];
  if (id[x] < 1) return;
  block::add(id[x], 1);
}
__attribute__((__always_inline__)) __inline void mo_del(int x) {
  x = sa[x];
  if (id[x] < 1) return;
  block::add(id[x], -1);
}
__attribute__((__always_inline__)) __inline pair<int, int> mo_ask(int l,
                                                                  int r) {
  return block::query(l, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(12);
  cin >> str >> n;
  for (int i = 1; i <= n; ++i) cin >> ttr[i];
  len = 0;
  for (const char &x : str) s[++len] = x, id[len] = 0;
  for (int i = 1; i <= n; ++i) {
    s[++len] = '$', id[len] = -1;
    for (const char &x : ttr[i]) s[++len] = x, id[len] = i;
  }
  SA::build(s, len, 128);
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    int l, r, pl, pr;
    cin >> l >> r >> pl >> pr;
    get_lcp_range(pl, pr - pl + 1, pl, pr);
    qry[i] = Query(pl, pr, l, r, i);
  }
  sort(qry + 1, qry + m + 1);
  block::init(Maxn - 5);
  int curL = 1, curR = 0;
  for (int i = 1; i <= m; ++i) {
    int l = qry[i].l, r = qry[i].r;
    while (curR < r) mo_add(++curR);
    while (curL > l) mo_add(--curL);
    while (curR > r) mo_del(curR--);
    while (curL < l) mo_del(curL++);
    ans[qry[i].id] = mo_ask(qry[i].vl, qry[i].vr);
  }
  for (int i = 1; i <= m; ++i) printf("%d %d\n", ans[i].second, ans[i].first);
  return 0;
}

### Prompt

Your task is to create a Cpp solution to the following problem:

The country of Reberland is the archenemy of Berland. Recently the authorities of Berland arrested a Reberlandian spy who tried to bring the leaflets intended for agitational propaganda to Berland illegally . The most leaflets contain substrings of the Absolutely Inadmissible Swearword and maybe even the whole word.

Berland legal system uses the difficult algorithm in order to determine the guilt of the spy. The main part of this algorithm is the following procedure.

All the m leaflets that are brought by the spy are numbered from 1 to m. After that it's needed to get the answer to q queries of the following kind: "In which leaflet in the segment of numbers [l, r] the substring of the Absolutely Inadmissible Swearword [pl, pr] occurs more often?".

The expert wants you to automate that procedure because this time texts of leaflets are too long. Help him!

Input

The first line contains the string s (1 ≤ |s| ≤ 5·105) — the Absolutely Inadmissible Swearword. The string s consists of only lowercase English letters.

The second line contains the only integer m (1 ≤ m ≤ 5·104) — the number of texts of leaflets for expertise.

Each of the next m lines contains the only string ti — the text of the i-th leaflet. The sum of lengths of all leaflet texts doesn't exceed 5·104. The text of the leaflets consists of only lowercase English letters.

The next line contains integer q (1 ≤ q ≤ 5·105) — the number of queries for expertise.

Finally, each of the last q lines contains four integers l, r, pl, pr (1 ≤ l ≤ r ≤ m, 1 ≤ pl ≤ pr ≤ |s|), where |s| is the length of the Absolutely Inadmissible Swearword.

Output

Print q lines. The i-th of them should contain two integers — the number of the text with the most occurences and the number of occurences of the substring [pl, pr] of the string s. If there are several text numbers print the smallest one.

Examples

Input

suffixtree
3
suffixtreesareawesome
cartesiantreeisworsethansegmenttree
nyeeheeheee
2
1 2 1 10
1 3 9 10


Output

1 1
3 4

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma GCC optimize("Ofast,-funroll-loops,-fno-stack-protector")
#pragma GCC target( \
    "popcnt,sse,sse2,sse3,ssse3,sse4,avx,avx2,abm,mmx,tune=native")
using namespace std;
static constexpr int Maxn = 1e5 + 5;
static constexpr int Maxs = 5e5 + 1e5 + 5;
static constexpr int Maxm = 5e5 + 5;
static constexpr int LOG = 20;
int n, m, len;
string str, ttr[Maxn];
char s[Maxs];
int id[Maxs];
pair<int, int> ans[Maxm];
namespace SA {
static constexpr int Maxn = ::Maxs;
static constexpr int LOG = ::LOG;
int wa[Maxn], wb[Maxn], wc[Maxn], _s[Maxn];
int sa[Maxn], rnk[Maxn], height[Maxn];
int ST[Maxn][LOG], N;
template <typename T>
void build(T *ss, int n, int m) {
  N = n;
  register int *x = wa, *y = wb, *tmp;
  register int i, j, w;
  for (i = 1; i <= n; ++i) _s[i] = ss[i];
  for (i = 1; i <= n; ++i) x[i] = _s[i], y[i] = i;
  for (i = 1; i <= m; ++i) wc[i] = 0;
  for (i = 1; i <= n; ++i) wc[x[i]]++;
  for (i = 2; i <= m; ++i) wc[i] += wc[i - 1];
  for (i = n; i >= 1; --i) sa[wc[x[y[i]]]--] = y[i];
  for (w = 1; w <= n; w <<= 1) {
    register int tot = 0;
    for (i = n - w + 1; i <= n; ++i) y[++tot] = i;
    for (i = 1; i <= n; ++i)
      if (sa[i] > w) y[++tot] = sa[i] - w;
    for (i = 1; i <= m; ++i) wc[i] = 0;
    for (i = 1; i <= n; ++i) wc[x[i]]++;
    for (i = 2; i <= m; ++i) wc[i] += wc[i - 1];
    for (i = n; i >= 1; --i) sa[wc[x[y[i]]]--] = y[i];
    tmp = x, x = y, y = tmp, x[sa[1]] = 1, tot = 1;
    for (i = 2; i <= n; ++i)
      x[sa[i]] = ((y[sa[i]] == y[sa[i - 1]] && y[sa[i] + w] == y[sa[i - 1] + w])
                      ? tot
                      : ++tot);
    if (tot == n) break;
    m = tot;
  }
  for (i = 1; i <= n; ++i) rnk[sa[i]] = i;
  for (i = 1, w = 0; i <= n; ++i) {
    if (rnk[i] == 1) continue;
    if (w) --w;
    int j = sa[rnk[i] - 1];
    while (i + w <= n && j + w <= n && _s[i + w] == _s[j + w]) w++;
    height[rnk[i]] = w;
  }
  for (int i = 1; i <= n; ++i) ST[i][0] = height[i];
  for (int j = 1; j < LOG; ++j)
    for (int i = 1; i + (1 << j) - 1 <= n; ++i)
      ST[i][j] = min(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
}
__attribute__((__always_inline__)) __inline int get_lcp(int x1, int x2) {
  if (x1 == x2) {
    return N - x1 + 1;
  } else {
    x1 = rnk[x1], x2 = rnk[x2];
    if (x1 > x2) swap(x1, x2);
    ++x1;
    int k = 31 - __builtin_clz(x2 - x1 + 1);
    return min(ST[x1][k], ST[x2 - (1 << k) + 1][k]);
  }
}
void get_lcp_range(int x, int len, int &l, int &r) {
  x = rnk[x], l = r = x;
  int j;
  for (j = 0; l - (1 << j) + 1 >= 2; ++j)
    ;
  for (; ~--j;) {
    if (l - (1 << j) + 1 >= 2 && ST[l - (1 << j) + 1][j] >= len) {
      l -= (1 << j);
    }
  }
  for (j = 0; r + (1 << j) <= N; ++j)
    ;
  for (; ~--j;) {
    if (r + (1 << j) <= N && ST[r + 1][j] >= len) {
      r += (1 << j);
    }
  }
}
}  // namespace SA
using SA::build;
using SA::get_lcp;
using SA::get_lcp_range;
using SA::height;
using SA::rnk;
using SA::sa;
struct Query {
  int l, r, vl, vr, id, block;
  Query() { memset(this, 0, sizeof(*this)); }
  Query(int l, int r, int vl, int vr, int id)
      : l(l), r(r), vl(vl), vr(vr), id(id) {
    block = ((l - 1) / (int)sqrt(len) / 2) + 1;
  }
  friend bool operator<(const Query &c, const Query &d) {
    return (c.block ^ d.block) ? c.block < d.block
                               : ((c.block & 1) ? c.r < d.r : c.r > d.r);
  }
  ~Query() = default;
} qry[Maxm];
bool cmp(pair<int, int> x, pair<int, int> y) {
  return x.first > y.first || (x.first == y.first && x.second < y.second);
}
namespace block {
static constexpr int Maxn = ::Maxn;
static constexpr int BLOCK = 400;
int blk, bls, bl[Maxn];
int bL[BLOCK], bR[Maxn];
int cnt[Maxn], cc[BLOCK][Maxn];
int ans[BLOCK];
__attribute__((__always_inline__)) __inline void add(int x, int val) {
  int b = bl[x];
  if (val == 1) {
    cc[b][cnt[x]]--;
    ++cnt[x];
    cc[b][cnt[x]]++;
    ans[b] = max(ans[b], cnt[x]);
  } else {
    cc[b][cnt[x]]--;
    --cnt[x];
    cc[b][cnt[x]]++;
    if (!cc[b][ans[b]]) ans[b]--;
  }
}
pair<int, int> query(int l, int r) {
  int pl = bl[l], pr = bl[r];
  if (pl == pr) {
    pair<int, int> res(0, l);
    for (int i = l; i <= r; ++i) res = min(res, make_pair(cnt[i], i), cmp);
    return res;
  }
  auto res = min(query(l, bR[pl]), query(bL[pr], r), cmp);
  if (pl + 1 == pr) {
    return res;
  } else {
    pair<int, int> rres(0, pl + 1);
    for (int b = pl + 1; b < pr; ++b)
      rres = min(rres, make_pair(ans[b], b), cmp);
    if (rres.first != 0) {
      int b = rres.second;
      for (int i = bL[b]; i <= bR[b]; ++i)
        if (cnt[i] == rres.first) {
          rres.second = i;
          break;
        }
    } else {
      rres.second = bL[rres.second];
    }
    return min(res, rres, cmp);
  }
}
void init(int len) {
  blk = 350;
  for (int i = 1; i <= len; ++i) bl[i] = (i - 1) / blk + 1;
  bls = bl[len];
  for (int i = 1; i <= bls; ++i) {
    bL[i] = (i - 1) * blk + 1;
    bR[i] = i * blk;
    if (bR[i] > len) bR[i] = len;
  }
  memset(ans, 0, sizeof(ans));
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= bls; ++i) cc[i][0] = 1e7;
}
}  // namespace block
__attribute__((__always_inline__)) __inline void mo_add(int x) {
  x = sa[x];
  if (id[x] < 1) return;
  block::add(id[x], 1);
}
__attribute__((__always_inline__)) __inline void mo_del(int x) {
  x = sa[x];
  if (id[x] < 1) return;
  block::add(id[x], -1);
}
__attribute__((__always_inline__)) __inline pair<int, int> mo_ask(int l,
                                                                  int r) {
  return block::query(l, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(12);
  cin >> str >> n;
  for (int i = 1; i <= n; ++i) cin >> ttr[i];
  len = 0;
  for (const char &x : str) s[++len] = x, id[len] = 0;
  for (int i = 1; i <= n; ++i) {
    s[++len] = '$', id[len] = -1;
    for (const char &x : ttr[i]) s[++len] = x, id[len] = i;
  }
  SA::build(s, len, 128);
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    int l, r, pl, pr;
    cin >> l >> r >> pl >> pr;
    get_lcp_range(pl, pr - pl + 1, pl, pr);
    qry[i] = Query(pl, pr, l, r, i);
  }
  sort(qry + 1, qry + m + 1);
  block::init(Maxn - 5);
  int curL = 1, curR = 0;
  for (int i = 1; i <= m; ++i) {
    int l = qry[i].l, r = qry[i].r;
    while (curR < r) mo_add(++curR);
    while (curL > l) mo_add(--curL);
    while (curR > r) mo_del(curR--);
    while (curL < l) mo_del(curL++);
    ans[qry[i].id] = mo_ask(qry[i].vl, qry[i].vr);
  }
  for (int i = 1; i <= m; ++i) printf("%d %d\n", ans[i].second, ans[i].first);
  return 0;
}

```