#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double pi = acosl(-1.), eps = 1e-9;
inline int power(int a, int b, int m = mod, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
const int NN = 200020;
int n;
char s[NN];
int rk[NN * 2], mn[NN * 2][22];
int ht[NN * 2], sa[NN * 2];
int head[NN << 1];
pair<pair<int, int>, int> pos[NN << 1], buf[NN << 1], tbuf[NN << 1];
int rgt[NN << 1];
void bucket_sort(int ok, int n) {
  int i, u, j, deg, E, K;
  for (i = E = K = 0; i < max(222, n + 10); i++) head[i] = -1;
  for (i = 0; i < n; i++) {
    if (ok)
      u = pos[i].first.first + 1;
    else
      u = pos[i].first.second + 1;
    buf[E] = pos[i];
    rgt[E] = head[u];
    head[u] = E++;
  }
  for (int i = 0; i < max(n + 10, 222); i++) {
    for (deg = 0, j = head[i]; ~j; j = rgt[j]) {
      tbuf[deg++] = buf[j];
    }
    while (deg) pos[K++] = tbuf[--deg];
  }
}
void LCP(int n) {
  for (int i = 1; i <= n; i++) mn[i][0] = ht[i];
  for (int j = 1; j < 22; j++) {
    for (int i = 1; i <= n; i++) {
      mn[i][j] = min(mn[i][j - 1], mn[min(n, i + (1 << j - 1))][j - 1]);
    }
  }
}
void height(int n) {
  int h = 0, i;
  for (i = 0; i < n; i++) sa[rk[i]] = i;
  for (i = 0; i < n; i++) {
    if (rk[i] == 1) continue;
    h = max(0, h - 1);
    for (int j = sa[rk[i] - 1]; s[i + h] == s[j + h]; h++)
      ;
    ht[rk[i]] = h;
  }
}
void buildSA(int n) {
  int i, j, cnt, u;
  for (i = 0; i < n; i++) rk[i] = s[i];
  rk[n] = 0;
  for (i = 0; i < 20; i++) {
    for (j = 0; j < n; j++)
      pos[j] = pair<pair<int, int>, int>(
          pair<int, int>(rk[j], rk[min(n, j + (1 << i))]), j);
    bucket_sort(0, n);
    bucket_sort(1, n);
    pos[n] = pair<pair<int, int>, int>(pair<int, int>(-1, -1), -1);
    for (cnt = j = 0; j < n; j++) {
      rk[pos[j].second] = cnt + 1;
      cnt += (pos[j].first != pos[j + 1].first);
    }
    if (cnt == n) break;
  }
  height(n);
  LCP(n);
}
int calc(int u, int v) {
  if (u == v) return n - sa[u];
  if (u > v) swap(u, v);
  u++;
  int l = 31 - (__builtin_clz(v - u + 1));
  return min(mn[u][l], mn[v - (1 << l) + 1][l]);
}
pair<int, int> v[NN << 1];
map<int, int> cnt;
map<int, int>::iterator it;
void solve(long long ans = 0) {
  int K, L, m = 0;
  scanf("%d%d", &K, &L);
  for (int i = 0, d; i < K; i++, m++) {
    scanf("%d", &d);
    v[m].first = d - 1;
    v[m].second = 1;
  }
  for (int i = 0, d; i < L; i++, m++) {
    scanf("%d", &d);
    v[m].first = d - 1;
    v[m].second = 0;
  }
  sort(v, v + m, [](pair<int, int> a, pair<int, int> b) {
    if (a.first == b.first) return a.second < b.second;
    return rk[a.first] < rk[b.first];
  });
  long long tmp = 0;
  pair<int, int> p;
  for (int step = 2; step--;) {
    cnt.clear();
    tmp = 0;
    for (int i = 0; i < m; i++) {
      if (!v[i].second) {
        ans += tmp;
      } else {
        cnt[n - v[i].first]++;
        tmp += n - v[i].first;
      }
      if (i == m - 1) break;
      L = calc(rk[v[i].first], rk[v[i + 1].first]);
      while (!cnt.empty()) {
        it = --cnt.end();
        p = *it;
        if (p.first <= L) break;
        cnt.erase(it);
        tmp -= (long long)p.second * (p.first - L);
        cnt[L] += p.second;
      }
    }
    reverse(v, v + m);
  }
  printf("%I64d\n", ans);
}
int main() {
  int Q;
  scanf("%d%d", &n, &Q);
  scanf("%s", s);
  buildSA(n);
  for (; Q--;) solve();
  return 0;
}
