#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1;
long long arr[N];
long long pos[N];
long long lcp[N];
namespace Suffix_Array {
void SA(string s) {
  s += "$";
  long long n = s.size();
  vector<long long> p(n);
  vector<long long> c(n);
  vector<long long> cnt(max(256ll, n), 0);
  for (char C : s) cnt[C]++;
  for (long long i = 1; i < 256; ++i) cnt[i] += cnt[i - 1];
  for (long long i = 0; i < n; ++i) p[--cnt[s[i]]] = i;
  c[p[0]] = 0;
  long long lop = 1;
  for (long long i = 1; i < n; ++i) {
    if (s[p[i]] != s[p[i - 1]]) ++lop;
    c[p[i]] = lop - 1;
  }
  vector<long long> pn(n);
  vector<long long> cn(n);
  for (long long k = 1; k < n; k <<= 1) {
    for (long long i = 0; i < n; ++i) pn[i] = (p[i] - k + n) % n;
    fill(cnt.begin(), cnt.begin() + lop, 0);
    for (long long i = 0; i < n; ++i) cnt[c[pn[i]]]++;
    for (long long i = 1; i < lop; ++i) cnt[i] += cnt[i - 1];
    for (long long i = n - 1; i >= 0; --i) p[--cnt[c[pn[i]]]] = pn[i];
    cn[p[0]] = 0;
    lop = 1;
    for (long long i = 1; i < n; ++i) {
      if (c[p[i]] != c[p[i - 1]] || c[(p[i] + k) % n] != c[(p[i - 1] + k) % n])
        ++lop;
      cn[p[i]] = lop - 1;
    }
    c.swap(cn);
  }
  p.erase(p.begin());
  n--;
  for (long long i = 0; i < n; ++i) arr[i] = p[i], pos[p[i]] = i;
}
void work(string s) {
  SA(s);
  long long n = s.size();
  long long len = 0;
  for (long long i = 0; i < n; ++i) {
    if (pos[i] == n - 1) continue;
    while (i + len < n && arr[pos[i] + 1] + len < n &&
           s[i + len] == s[arr[pos[i] + 1] + len])
      ++len;
    lcp[pos[i]] = len;
    len = max(0ll, len - 1);
  }
}
};  // namespace Suffix_Array
long long it[N << 2];
long long lz[N << 2];
void push(long long i, long long l, long long r) {
  if (lz[i] < 0) return;
  it[i] = (r - l + 1) * lz[i];
  if (l != r) {
    lz[i << 1] = lz[i];
    lz[i << 1 | 1] = lz[i];
  }
  lz[i] = -1;
}
void upd(long long i, long long l, long long r, long long L, long long R,
         long long v) {
  push(i, l, r);
  if (l > R || r < L) return;
  if (L <= l && r <= R) {
    lz[i] = v;
    push(i, l, r);
    return;
  }
  long long m = (l + r) / 2;
  upd(i << 1, l, m, L, R, v);
  ++m;
  upd(i << 1 | 1, m, r, L, R, v);
  it[i] = it[i << 1] + it[i << 1 | 1];
}
long long n, q;
string s;
long long rmq[N][20];
long long get(long long l, long long r) {
  if (l == r) return n - arr[l];
  if (l > r) swap(l, r);
  long long k = log2(r - l);
  return min(rmq[l][k], rmq[r - (1 << k)][k]);
}
bool Q = 0;
bool cmp(long long x, long long y) { return (Q ^ (x <= y)); }
long long a[N], b[N];
void work() {
  long long n1, n2;
  cin >> n1 >> n2;
  for (long long i = 1; i <= n1; ++i) cin >> a[i], a[i] = pos[a[i] - 1];
  for (long long i = 1; i <= n2; ++i) cin >> b[i], b[i] = pos[b[i] - 1];
  sort(a + 1, a + 1 + n1);
  sort(b + 1, b + 1 + n2);
  long long ans = 0;
  for (long long t = 0; t < 2; ++t) {
    long long p = 0;
    upd(1, 1, n2, 1, n2, 0);
    for (long long i = 1; i <= n1; ++i) {
      if (i > 1) {
        long long x = get(a[i - 1], a[i]);
        long long l = 1, r = p + 1;
        while (l < r) {
          long long m = (l + r) / 2;
          if (get(b[m], a[i - 1]) >= x)
            r = m;
          else
            l = m + 1;
        }
        upd(1, 1, n2, l, p, x);
      }
      while (p < n2 && cmp(b[p + 1], a[i])) {
        ++p;
        upd(1, 1, n2, p, p, get(b[p], a[i]));
      }
      ans += it[1];
    }
    reverse(a + 1, a + 1 + n1);
    reverse(b + 1, b + 1 + n2);
    Q ^= 1;
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q >> s;
  Suffix_Array::work(s);
  for (long long i = 0; i < n; ++i) rmq[i][0] = lcp[i];
  for (long long i = 0; i < 18; ++i)
    for (long long j = 0; j + (2 << i) <= n; ++j)
      rmq[j][i + 1] = min(rmq[j][i], rmq[j + (1 << i)][i]);
  while (q--) work();
}
