#include <bits/stdc++.h>
inline int min(const int &first, const int &second) {
  return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first;
}
inline int max(const int &first, const int &second) {
  return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second;
}
inline long long min(const long long &first, const long long &second) {
  return (((second - first) >> (64 - 1)) & (first ^ second)) ^ first;
}
inline long long max(const long long &first, const long long &second) {
  return (((second - first) >> (64 - 1)) & (first ^ second)) ^ second;
}
using namespace std;
char string_in_buffer[(int)2e6];
void fast_scan(int &first) { scanf("%d", &first); }
void fast_scan(long long &first) { scanf("%lld", &first); }
void fast_scan(unsigned long long &first) { scanf("%llu", &first); }
void fast_scan(double &first) { scanf("%lf", &first); }
void fast_scan(long double &first) { scanf("%Lf", &first); }
void fast_scan(char &first) {
  scanf("%c", &first);
  if (first == '\n') {
    fast_scan(first);
  }
}
void fast_scan(string &first) {
  scanf("%s", string_in_buffer);
  first = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
  fast_scan(p.first);
  fast_scan(p.second);
}
template <class T>
void fast_scan(vector<T> &v) {
  for (auto &first : v) fast_scan(first);
}
void fast_print(const int &first) { printf("%d", first); }
void fast_print(const unsigned int &first) { printf("%u", first); }
void fast_print(const long long &first) { printf("%lld", first); }
void fast_print(const unsigned long long &first) { printf("%llu", first); }
void fast_print(const char &first) { printf("%c", first); };
void fast_print(const double &first) { printf("%.15lf", first); }
void fast_print(const long double &first) { printf("%.15Lf", first); }
void fast_print(const string &first) { printf("%s", first.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
  fast_print(p.first);
  fast_print(' ');
  fast_print(p.second);
}
template <class T>
void fast_print(const vector<T> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print(' ');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const vector<vector<T>> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print('\n');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const T &v) {
  for (const auto &first : v) {
    fast_print(first);
    fast_print(' ');
  }
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
  fast_print(print_start);
  print_start = "\n";
  first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
  if (!first_print) {
    fast_print("\n");
  } else {
    first_print = false;
  }
  fast_print(names.front());
  fast_print(" = ");
  fast_print(elem);
  names.pop_front();
  _print(names, args...);
}
}  // namespace smart_io
template <class T>
ostream &operator,(ostream &os, const T &object) {
  if (!smart_io::first_print) {
    fast_print(smart_io::sep);
  } else {
    smart_io::first_print = false;
  }
  fast_print(object);
  return os;
}
template <class T>
istream &operator,(istream &is, T &object) {
  fast_scan(object);
  return is;
}
namespace escape__from__random__aetuhoetnuhshe {
using namespace std::chrono;
mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
                .count());
uniform_real_distribution<> prob_dist(0.0, 1.0);
};  // namespace escape__from__random__aetuhoetnuhshe
namespace typedefs {}
namespace numbers_operation {
template <class T>
inline T floor_mod(T a, const T &b) {
  a %= b;
  if (a < 0) a += b;
  return a;
}
}  // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
using namespace escape__from__random__aetuhoetnuhshe;
const int AL = 26;
const int SYM = 'a';
struct SA {
  vector<int> sf;
  vector<array<int, AL>> go;
  vector<int> len;
  vector<bool> hit;
  vector<long long> ends;
  vector<bool> used;
  vector<vector<pair<int, long long>>> bells;
  int newn() {
    sf.push_back(-1);
    go.emplace_back(array<int, AL>());
    go.back().fill(-1);
    len.push_back(0);
    hit.push_back(false);
    used.push_back(false);
    ends.emplace_back(0);
    bells.push_back({});
    return sf.size() - 1;
  }
  SA() { newn(); }
  void upload_string(string s) {
    int cur = 0;
    for (int i = 0; i < s.size(); ++i) {
      int pos = cur;
      int c = s[i] - SYM;
      int nw = newn();
      len[nw] = i + 1;
      while (cur != -1 && go[cur][c] == -1) go[cur][c] = nw, cur = sf[cur];
      if (cur == -1)
        sf[nw] = 0;
      else {
        int q = go[cur][c];
        if (len[q] == len[cur] + 1)
          sf[nw] = q;
        else {
          int cl = len.size();
          len.push_back(len[cur] + 1);
          go.push_back(go[q]);
          sf.push_back(sf[q]);
          hit.push_back(false);
          used.push_back(false);
          ends.emplace_back(0);
          bells.push_back({});
          sf[q] = sf[nw] = cl;
          while (cur != -1 && go[cur][c] == q) go[cur][c] = cl, cur = sf[cur];
        }
      }
      cur = go[pos][c];
    }
  }
  void Belfast(int i, int id) {
    used[i] = true;
    for (int c = 0; c < AL; c++) {
      if (go[i][c] != -1 && hit[go[i][c]]) {
        if (!used[go[i][c]]) Belfast(go[i][c], id);
        ends[i] += ends[go[i][c]];
      }
    }
    bells[i].emplace_back(id, ends[i]);
  }
  void clear_work(int i) {
    hit[i] = false;
    ends[i] = 0;
    used[i] = false;
    for (int c = 0; c < AL; c++) {
      if (go[i][c] != -1 && hit[go[i][c]]) {
        if (used[go[i][c]]) clear_work(go[i][c]);
      }
    }
  }
  void examine(string s, int id) {
    int cur = 0;
    for (int i = 0; i < ((int)s.size()); i++) {
      int c = s[i] - SYM;
      cur = go[cur][c];
      int sub = cur;
      while (sub != -1 && !hit[sub]) {
        hit[sub] = true;
        sub = sf[sub];
      }
    }
    while (cur != -1) {
      ends[cur]++;
      cur = sf[cur];
    }
    Belfast(0, id);
    clear_work(0);
  }
};
signed main(signed argc, char *argv[]) {
  string s;
  cin, s;
  int m;
  cin, m;
  vector<string> v(m);
  cin, v;
  SA sat;
  sat.upload_string(s);
  for (string t : v) sat.upload_string(t);
  for (int i = 0; i < m; i++) sat.examine(v[i], i);
  vector<int> nodes;
  {
    int cur = 0;
    for (int i = 0; i < ((int)s.size()); i++) {
      int c = s[i] - SYM;
      cur = sat.go[cur][c];
      nodes.push_back(cur);
    }
  }
  int q;
  cin, q;
  for (int i = 0; i < (q); i++) {
    int l, r, pl, pr;
    cin, l, r, pl, pr;
    l--, pl--;
    swap(l, pl);
    swap(r, pr);
    int cur = nodes[r - 1];
    while (sat.len[sat.sf[cur]] >= r - l) {
      cur = sat.sf[cur];
    }
    pair<long long, int> rez = make_pair(0, pl);
    for (auto p : sat.bells[cur])
      if (pl <= p.first && p.first < pr)
        if (rez.first < p.second) rez = make_pair(p.second, p.first);
    smart_io::precall_print();
    cout, rez.second + 1, rez.first;
  }
}

### Prompt

Develop a solution in CPP to the problem described below:

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>
inline int min(const int &first, const int &second) {
  return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first;
}
inline int max(const int &first, const int &second) {
  return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second;
}
inline long long min(const long long &first, const long long &second) {
  return (((second - first) >> (64 - 1)) & (first ^ second)) ^ first;
}
inline long long max(const long long &first, const long long &second) {
  return (((second - first) >> (64 - 1)) & (first ^ second)) ^ second;
}
using namespace std;
char string_in_buffer[(int)2e6];
void fast_scan(int &first) { scanf("%d", &first); }
void fast_scan(long long &first) { scanf("%lld", &first); }
void fast_scan(unsigned long long &first) { scanf("%llu", &first); }
void fast_scan(double &first) { scanf("%lf", &first); }
void fast_scan(long double &first) { scanf("%Lf", &first); }
void fast_scan(char &first) {
  scanf("%c", &first);
  if (first == '\n') {
    fast_scan(first);
  }
}
void fast_scan(string &first) {
  scanf("%s", string_in_buffer);
  first = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
  fast_scan(p.first);
  fast_scan(p.second);
}
template <class T>
void fast_scan(vector<T> &v) {
  for (auto &first : v) fast_scan(first);
}
void fast_print(const int &first) { printf("%d", first); }
void fast_print(const unsigned int &first) { printf("%u", first); }
void fast_print(const long long &first) { printf("%lld", first); }
void fast_print(const unsigned long long &first) { printf("%llu", first); }
void fast_print(const char &first) { printf("%c", first); };
void fast_print(const double &first) { printf("%.15lf", first); }
void fast_print(const long double &first) { printf("%.15Lf", first); }
void fast_print(const string &first) { printf("%s", first.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
  fast_print(p.first);
  fast_print(' ');
  fast_print(p.second);
}
template <class T>
void fast_print(const vector<T> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print(' ');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const vector<vector<T>> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print('\n');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const T &v) {
  for (const auto &first : v) {
    fast_print(first);
    fast_print(' ');
  }
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
  fast_print(print_start);
  print_start = "\n";
  first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
  if (!first_print) {
    fast_print("\n");
  } else {
    first_print = false;
  }
  fast_print(names.front());
  fast_print(" = ");
  fast_print(elem);
  names.pop_front();
  _print(names, args...);
}
}  // namespace smart_io
template <class T>
ostream &operator,(ostream &os, const T &object) {
  if (!smart_io::first_print) {
    fast_print(smart_io::sep);
  } else {
    smart_io::first_print = false;
  }
  fast_print(object);
  return os;
}
template <class T>
istream &operator,(istream &is, T &object) {
  fast_scan(object);
  return is;
}
namespace escape__from__random__aetuhoetnuhshe {
using namespace std::chrono;
mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
                .count());
uniform_real_distribution<> prob_dist(0.0, 1.0);
};  // namespace escape__from__random__aetuhoetnuhshe
namespace typedefs {}
namespace numbers_operation {
template <class T>
inline T floor_mod(T a, const T &b) {
  a %= b;
  if (a < 0) a += b;
  return a;
}
}  // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
using namespace escape__from__random__aetuhoetnuhshe;
const int AL = 26;
const int SYM = 'a';
struct SA {
  vector<int> sf;
  vector<array<int, AL>> go;
  vector<int> len;
  vector<bool> hit;
  vector<long long> ends;
  vector<bool> used;
  vector<vector<pair<int, long long>>> bells;
  int newn() {
    sf.push_back(-1);
    go.emplace_back(array<int, AL>());
    go.back().fill(-1);
    len.push_back(0);
    hit.push_back(false);
    used.push_back(false);
    ends.emplace_back(0);
    bells.push_back({});
    return sf.size() - 1;
  }
  SA() { newn(); }
  void upload_string(string s) {
    int cur = 0;
    for (int i = 0; i < s.size(); ++i) {
      int pos = cur;
      int c = s[i] - SYM;
      int nw = newn();
      len[nw] = i + 1;
      while (cur != -1 && go[cur][c] == -1) go[cur][c] = nw, cur = sf[cur];
      if (cur == -1)
        sf[nw] = 0;
      else {
        int q = go[cur][c];
        if (len[q] == len[cur] + 1)
          sf[nw] = q;
        else {
          int cl = len.size();
          len.push_back(len[cur] + 1);
          go.push_back(go[q]);
          sf.push_back(sf[q]);
          hit.push_back(false);
          used.push_back(false);
          ends.emplace_back(0);
          bells.push_back({});
          sf[q] = sf[nw] = cl;
          while (cur != -1 && go[cur][c] == q) go[cur][c] = cl, cur = sf[cur];
        }
      }
      cur = go[pos][c];
    }
  }
  void Belfast(int i, int id) {
    used[i] = true;
    for (int c = 0; c < AL; c++) {
      if (go[i][c] != -1 && hit[go[i][c]]) {
        if (!used[go[i][c]]) Belfast(go[i][c], id);
        ends[i] += ends[go[i][c]];
      }
    }
    bells[i].emplace_back(id, ends[i]);
  }
  void clear_work(int i) {
    hit[i] = false;
    ends[i] = 0;
    used[i] = false;
    for (int c = 0; c < AL; c++) {
      if (go[i][c] != -1 && hit[go[i][c]]) {
        if (used[go[i][c]]) clear_work(go[i][c]);
      }
    }
  }
  void examine(string s, int id) {
    int cur = 0;
    for (int i = 0; i < ((int)s.size()); i++) {
      int c = s[i] - SYM;
      cur = go[cur][c];
      int sub = cur;
      while (sub != -1 && !hit[sub]) {
        hit[sub] = true;
        sub = sf[sub];
      }
    }
    while (cur != -1) {
      ends[cur]++;
      cur = sf[cur];
    }
    Belfast(0, id);
    clear_work(0);
  }
};
signed main(signed argc, char *argv[]) {
  string s;
  cin, s;
  int m;
  cin, m;
  vector<string> v(m);
  cin, v;
  SA sat;
  sat.upload_string(s);
  for (string t : v) sat.upload_string(t);
  for (int i = 0; i < m; i++) sat.examine(v[i], i);
  vector<int> nodes;
  {
    int cur = 0;
    for (int i = 0; i < ((int)s.size()); i++) {
      int c = s[i] - SYM;
      cur = sat.go[cur][c];
      nodes.push_back(cur);
    }
  }
  int q;
  cin, q;
  for (int i = 0; i < (q); i++) {
    int l, r, pl, pr;
    cin, l, r, pl, pr;
    l--, pl--;
    swap(l, pl);
    swap(r, pr);
    int cur = nodes[r - 1];
    while (sat.len[sat.sf[cur]] >= r - l) {
      cur = sat.sf[cur];
    }
    pair<long long, int> rez = make_pair(0, pl);
    for (auto p : sat.bells[cur])
      if (pl <= p.first && p.first < pr)
        if (rez.first < p.second) rez = make_pair(p.second, p.first);
    smart_io::precall_print();
    cout, rez.second + 1, rez.first;
  }
}

```