#include <bits/stdc++.h>
namespace Quick {
class InStream {
 private:
  char buf[1 << 21], *p1, *p2, failed;
  inline char getc() {
    return p1 == p2 &&
                   (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
               ? EOF
               : *p1++;
  }
  template <class Type>
  inline int read(Type &x) {
    bool k = false;
    char c = getc();
    for (; !isdigit(c); c = getc()) {
      k |= (c == '-');
      if (c == EOF) return 0;
    }
    x = 0;
    for (; isdigit(c); c = getc()) x = (x << 1) + (x << 3) + (c ^ 48);
    x *= (k ? -1 : 1);
    return 1;
  }
  inline int read(char *s) {
    *s = getc();
    for (; isspace(*s) || *s == EOF; *s = getc())
      if (*s == EOF) return 0;
    for (; !isspace(*s) && *s != EOF; *s = getc()) s++;
    *s = '\0';
    return 1;
  }

 public:
  operator int() const { return ~failed; }
  InStream() {
    p1 = p2 = buf;
    failed = 0x00;
  }
  ~InStream() {}
  template <class Type>
  InStream &operator>>(Type &&x) {
    if (read(x))
      failed = 0x00;
    else
      failed = 0xff;
    return *this;
  }
} cin;
class OutStream {
 private:
  char buf[1 << 21];
  int p1;
  const int p2 = 1 << 21;
  inline void flush() {
    fwrite(buf, 1, p1, stdout);
    p1 = 0;
  }
  inline void putc(const char &c) {
    if (p1 == p2) flush();
    buf[p1++] = c;
  }
  template <class Type>
  inline void write(Type x) {
    static char buf[25];
    int p = -1;
    if (x < 0) {
      x *= -1;
      putc('-');
    }
    if (x == 0)
      putc('0');
    else
      for (; x; x /= 10) buf[++p] = x % 10 + 48;
    while (~p) putc(buf[p--]);
  }
  inline void write(char *s) {
    for (; *s; s++) putc(*s);
  }
  inline void write(const char *s) {
    for (; *s; s++) putc(*s);
  }
  inline void write(const char &c) { putc(c); }

 public:
  OutStream() { p1 = 0; }
  ~OutStream() { flush(); }
  template <class Type>
  OutStream &operator<<(const Type &x) {
    write(x);
    return *this;
  }
} cout;
const char endl('\n');
template <class Type>
inline Type max(const Type &a, const Type &b) {
  if (a < b) return b;
  return a;
}
template <class Type>
inline Type min(const Type &a, const Type &b) {
  if (a < b) return a;
  return b;
}
template <class Type>
inline void swap(Type &a, Type &b) {
  static Type tmp;
  tmp = a;
  a = b;
  b = tmp;
}
template <class Type>
inline Type abs(const Type &a) {
  return a >= 0 ? a : -a;
}
}  // namespace Quick
using namespace Quick;
const int maxn(5e5 + 10), maxm(5e4 + 10);
int n, m, q;
char s[maxn];
namespace SegmentTree {
struct Node {
  int val, pos;
  bool operator<(const Node &p) const {
    return (this->val ^ p.val) ? this->val < p.val : this->pos > p.pos;
  }
} st[maxm << 5];
int lc[maxm << 5], rc[maxm << 5], Node_Cnt;
inline void pushup(const int &a) { st[a] = max(st[lc[a]], st[rc[a]]); }
void Modify(const int &p, const int &k, int &a, const int &l = 1,
            const int &r = m) {
  if (!a) a = ++Node_Cnt;
  if (l == r) {
    st[a].val += k;
    st[a].pos = l;
    return;
  }
  int mid((l + r) >> 1);
  if (p <= mid)
    Modify(p, k, lc[a], l, mid);
  else
    Modify(p, k, rc[a], mid + 1, r);
  pushup(a);
}
Node Query(const int &left, const int &right, const int &a, const int &l = 1,
           const int &r = m) {
  if (!a) return st[0];
  if (left <= l && right >= r) return st[a];
  int mid((l + r) >> 1);
  if (right <= mid) return Query(left, right, lc[a], l, mid);
  if (left > mid) return Query(left, right, rc[a], mid + 1, r);
  return max(Query(left, right, lc[a], l, mid),
             Query(left, right, rc[a], mid + 1, r));
}
int Merge(int &a, int &b, const int &l = 1, const int &r = m) {
  if (!a || !b) return a | b;
  int cur(++Node_Cnt);
  if (l == r)
    st[cur].val = st[a].val + st[b].val, st[cur].pos = l;
  else {
    int mid((l + r) >> 1);
    lc[cur] = Merge(lc[a], lc[b], l, mid);
    rc[cur] = Merge(rc[a], rc[b], mid + 1, r);
    pushup(cur);
  }
  return cur;
}
int root[(maxn + maxm) << 1];
}  // namespace SegmentTree
using SegmentTree::root;
namespace exSAM {
struct Node {
  int link, next[26], len;
} st[(maxn + maxm) << 1];
int Node_Cnt;
void Init() { st[Node_Cnt++].link = -1; }
inline int CopyNode(int &p, const int &q, const int &c) {
  int clone(Node_Cnt++);
  st[clone] = st[q];
  st[clone].len = st[p].len + 1;
  for (; ~p && st[p].next[c] == q; p = st[p].link) st[p].next[c] = clone;
  return st[q].link = clone;
}
inline int Insert(const int &c, const int &last) {
  int p(last);
  if (st[last].next[c]) {
    int cur(st[last].next[c]);
    if (st[p].len + 1 == st[cur].len) return cur;
    return CopyNode(p, cur, c);
  }
  int cur(Node_Cnt++);
  st[cur].len = st[p].len + 1;
  for (; ~p && !st[p].next[c]; p = st[p].link) st[p].next[c] = cur;
  if (~p) {
    int q(st[p].next[c]);
    if (st[p].len + 1 == st[q].len)
      st[cur].link = q;
    else
      st[cur].link = CopyNode(p, q, c);
  }
  return cur;
}
int pos[maxn];
}  // namespace exSAM
using exSAM::pos;
namespace Graph {
struct Edge {
  int v, next;
  Edge(const int &v, const int &next) : v(v), next(next) {}
  Edge() {}
} e[(maxn + maxm) << 1];
int head[(maxn + maxm) << 1], cnt;
inline void AddEdge(const int &u, const int &v) {
  e[++cnt] = Edge(v, head[u]);
  head[u] = cnt;
}
int p[(maxn + maxm) << 1][21], depth[(maxn + maxm) << 1];
void Dfs(const int &u = 0) {
  depth[u] = depth[p[u][0]] + 1;
  for (int i(1); i < 21; i++) p[u][i] = p[p[u][i - 1]][i - 1];
  for (int i(head[u]); i; i = e[i].next) {
    const int &v(e[i].v);
    p[v][0] = u;
    Dfs(v);
    root[u] = SegmentTree::Merge(root[u], root[v]);
  }
}
inline int Find(int u, const int &len) {
  for (int i(20); ~i; i--)
    if (p[u][i] && exSAM::st[p[u][i]].len >= len) u = p[u][i];
  return u;
}
}  // namespace Graph
inline SegmentTree::Node Query(const int &l, const int &r, const int &lp,
                               const int &rp) {
  int u(Graph::Find(pos[rp], rp - lp + 1));
  return SegmentTree::Query(l, r, root[u]);
}
int main(void) {
  exSAM::Init();
  cin >> (s + 1);
  n = strlen(s + 1);
  for (int i(1); i <= n; i++) pos[i] = exSAM::Insert(s[i] - 'a', pos[i - 1]);
  cin >> m;
  SegmentTree::st[0].pos = m + 1;
  for (int i(1), now; i <= m; i++) {
    now = 0;
    cin >> (s + 1);
    n = strlen(s + 1);
    for (int j(1); j <= n; j++)
      SegmentTree::Modify(i, 1, root[now = exSAM::Insert(s[j] - 'a', now)]);
  }
  for (int i(1); i < exSAM::Node_Cnt; i++) Graph::AddEdge(exSAM::st[i].link, i);
  Graph::Dfs();
  cin >> q;
  for (int i(1); i <= q; i++) {
    int l, r, lp, rp;
    cin >> l >> r >> lp >> rp;
    SegmentTree::Node &&ans(Query(l, r, lp, rp));
    if (!ans.val) ans.pos = l;
    cout << ans.pos << ' ' << ans.val << endl;
  }
  return 0;
}

### Prompt

Please formulate 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>
namespace Quick {
class InStream {
 private:
  char buf[1 << 21], *p1, *p2, failed;
  inline char getc() {
    return p1 == p2 &&
                   (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
               ? EOF
               : *p1++;
  }
  template <class Type>
  inline int read(Type &x) {
    bool k = false;
    char c = getc();
    for (; !isdigit(c); c = getc()) {
      k |= (c == '-');
      if (c == EOF) return 0;
    }
    x = 0;
    for (; isdigit(c); c = getc()) x = (x << 1) + (x << 3) + (c ^ 48);
    x *= (k ? -1 : 1);
    return 1;
  }
  inline int read(char *s) {
    *s = getc();
    for (; isspace(*s) || *s == EOF; *s = getc())
      if (*s == EOF) return 0;
    for (; !isspace(*s) && *s != EOF; *s = getc()) s++;
    *s = '\0';
    return 1;
  }

 public:
  operator int() const { return ~failed; }
  InStream() {
    p1 = p2 = buf;
    failed = 0x00;
  }
  ~InStream() {}
  template <class Type>
  InStream &operator>>(Type &&x) {
    if (read(x))
      failed = 0x00;
    else
      failed = 0xff;
    return *this;
  }
} cin;
class OutStream {
 private:
  char buf[1 << 21];
  int p1;
  const int p2 = 1 << 21;
  inline void flush() {
    fwrite(buf, 1, p1, stdout);
    p1 = 0;
  }
  inline void putc(const char &c) {
    if (p1 == p2) flush();
    buf[p1++] = c;
  }
  template <class Type>
  inline void write(Type x) {
    static char buf[25];
    int p = -1;
    if (x < 0) {
      x *= -1;
      putc('-');
    }
    if (x == 0)
      putc('0');
    else
      for (; x; x /= 10) buf[++p] = x % 10 + 48;
    while (~p) putc(buf[p--]);
  }
  inline void write(char *s) {
    for (; *s; s++) putc(*s);
  }
  inline void write(const char *s) {
    for (; *s; s++) putc(*s);
  }
  inline void write(const char &c) { putc(c); }

 public:
  OutStream() { p1 = 0; }
  ~OutStream() { flush(); }
  template <class Type>
  OutStream &operator<<(const Type &x) {
    write(x);
    return *this;
  }
} cout;
const char endl('\n');
template <class Type>
inline Type max(const Type &a, const Type &b) {
  if (a < b) return b;
  return a;
}
template <class Type>
inline Type min(const Type &a, const Type &b) {
  if (a < b) return a;
  return b;
}
template <class Type>
inline void swap(Type &a, Type &b) {
  static Type tmp;
  tmp = a;
  a = b;
  b = tmp;
}
template <class Type>
inline Type abs(const Type &a) {
  return a >= 0 ? a : -a;
}
}  // namespace Quick
using namespace Quick;
const int maxn(5e5 + 10), maxm(5e4 + 10);
int n, m, q;
char s[maxn];
namespace SegmentTree {
struct Node {
  int val, pos;
  bool operator<(const Node &p) const {
    return (this->val ^ p.val) ? this->val < p.val : this->pos > p.pos;
  }
} st[maxm << 5];
int lc[maxm << 5], rc[maxm << 5], Node_Cnt;
inline void pushup(const int &a) { st[a] = max(st[lc[a]], st[rc[a]]); }
void Modify(const int &p, const int &k, int &a, const int &l = 1,
            const int &r = m) {
  if (!a) a = ++Node_Cnt;
  if (l == r) {
    st[a].val += k;
    st[a].pos = l;
    return;
  }
  int mid((l + r) >> 1);
  if (p <= mid)
    Modify(p, k, lc[a], l, mid);
  else
    Modify(p, k, rc[a], mid + 1, r);
  pushup(a);
}
Node Query(const int &left, const int &right, const int &a, const int &l = 1,
           const int &r = m) {
  if (!a) return st[0];
  if (left <= l && right >= r) return st[a];
  int mid((l + r) >> 1);
  if (right <= mid) return Query(left, right, lc[a], l, mid);
  if (left > mid) return Query(left, right, rc[a], mid + 1, r);
  return max(Query(left, right, lc[a], l, mid),
             Query(left, right, rc[a], mid + 1, r));
}
int Merge(int &a, int &b, const int &l = 1, const int &r = m) {
  if (!a || !b) return a | b;
  int cur(++Node_Cnt);
  if (l == r)
    st[cur].val = st[a].val + st[b].val, st[cur].pos = l;
  else {
    int mid((l + r) >> 1);
    lc[cur] = Merge(lc[a], lc[b], l, mid);
    rc[cur] = Merge(rc[a], rc[b], mid + 1, r);
    pushup(cur);
  }
  return cur;
}
int root[(maxn + maxm) << 1];
}  // namespace SegmentTree
using SegmentTree::root;
namespace exSAM {
struct Node {
  int link, next[26], len;
} st[(maxn + maxm) << 1];
int Node_Cnt;
void Init() { st[Node_Cnt++].link = -1; }
inline int CopyNode(int &p, const int &q, const int &c) {
  int clone(Node_Cnt++);
  st[clone] = st[q];
  st[clone].len = st[p].len + 1;
  for (; ~p && st[p].next[c] == q; p = st[p].link) st[p].next[c] = clone;
  return st[q].link = clone;
}
inline int Insert(const int &c, const int &last) {
  int p(last);
  if (st[last].next[c]) {
    int cur(st[last].next[c]);
    if (st[p].len + 1 == st[cur].len) return cur;
    return CopyNode(p, cur, c);
  }
  int cur(Node_Cnt++);
  st[cur].len = st[p].len + 1;
  for (; ~p && !st[p].next[c]; p = st[p].link) st[p].next[c] = cur;
  if (~p) {
    int q(st[p].next[c]);
    if (st[p].len + 1 == st[q].len)
      st[cur].link = q;
    else
      st[cur].link = CopyNode(p, q, c);
  }
  return cur;
}
int pos[maxn];
}  // namespace exSAM
using exSAM::pos;
namespace Graph {
struct Edge {
  int v, next;
  Edge(const int &v, const int &next) : v(v), next(next) {}
  Edge() {}
} e[(maxn + maxm) << 1];
int head[(maxn + maxm) << 1], cnt;
inline void AddEdge(const int &u, const int &v) {
  e[++cnt] = Edge(v, head[u]);
  head[u] = cnt;
}
int p[(maxn + maxm) << 1][21], depth[(maxn + maxm) << 1];
void Dfs(const int &u = 0) {
  depth[u] = depth[p[u][0]] + 1;
  for (int i(1); i < 21; i++) p[u][i] = p[p[u][i - 1]][i - 1];
  for (int i(head[u]); i; i = e[i].next) {
    const int &v(e[i].v);
    p[v][0] = u;
    Dfs(v);
    root[u] = SegmentTree::Merge(root[u], root[v]);
  }
}
inline int Find(int u, const int &len) {
  for (int i(20); ~i; i--)
    if (p[u][i] && exSAM::st[p[u][i]].len >= len) u = p[u][i];
  return u;
}
}  // namespace Graph
inline SegmentTree::Node Query(const int &l, const int &r, const int &lp,
                               const int &rp) {
  int u(Graph::Find(pos[rp], rp - lp + 1));
  return SegmentTree::Query(l, r, root[u]);
}
int main(void) {
  exSAM::Init();
  cin >> (s + 1);
  n = strlen(s + 1);
  for (int i(1); i <= n; i++) pos[i] = exSAM::Insert(s[i] - 'a', pos[i - 1]);
  cin >> m;
  SegmentTree::st[0].pos = m + 1;
  for (int i(1), now; i <= m; i++) {
    now = 0;
    cin >> (s + 1);
    n = strlen(s + 1);
    for (int j(1); j <= n; j++)
      SegmentTree::Modify(i, 1, root[now = exSAM::Insert(s[j] - 'a', now)]);
  }
  for (int i(1); i < exSAM::Node_Cnt; i++) Graph::AddEdge(exSAM::st[i].link, i);
  Graph::Dfs();
  cin >> q;
  for (int i(1); i <= q; i++) {
    int l, r, lp, rp;
    cin >> l >> r >> lp >> rp;
    SegmentTree::Node &&ans(Query(l, r, lp, rp));
    if (!ans.val) ans.pos = l;
    cout << ans.pos << ' ' << ans.val << endl;
  }
  return 0;
}

```