#include <bits/stdc++.h>
using namespace std;
const int N = 400005, M = 26;
struct edge {
  int v, nt;
};
int q[N], ind = 0, n, m, k, pos[N], x, l, tot = 0, a[N], b[N];
char s[N];
long long ans = 0;
struct graph {
  edge e[N];
  int h[N], cnt;
  int fa[N], id[N], sz[N], top[N], son[N], dep[N], tot;
  void init() {
    cnt = 0;
    tot = 0;
  }
  inline void add(int u, int v) {
    e[++cnt] = (edge){v, h[u]};
    h[u] = cnt;
  }
  inline void dfs1(int u) {
    id[u] = ++tot;
    for (int i = h[u]; i; i = e[i].nt) {
      int v = e[i].v;
      if (v == fa[u]) continue;
      sz[v] = 1;
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs1(v);
      sz[u] += sz[v];
      if (sz[son[u]] < sz[v]) son[u] = v;
    }
  }
  inline void dfs2(int u, int ntop) {
    top[u] = ntop;
    if (son[u]) dfs2(son[u], ntop);
    for (int i = h[u]; i; i = e[i].nt) {
      int v = e[i].v;
      if (v == fa[u] || v == son[u]) continue;
      dfs2(v, v);
    }
  }
  inline void mkrt(int u) {
    dep[u] = 1;
    fa[u] = 0;
    sz[u] = 1;
    dfs1(u);
    dfs2(u, u);
  }
  int lca(int x, int y) {
    while (top[x] != top[y]) {
      if (dep[top[x]] < dep[top[y]]) swap(x, y);
      x = fa[top[x]];
    }
    return dep[x] < dep[y] ? x : y;
  }
} t;
struct sam {
  int ch[N][M], fa[N], len[N], lst, gt;
  void init() { lst = gt = 1; }
  void ins(int c) {
    int f = lst, p = ++gt;
    lst = p;
    len[p] = len[f] + 1;
    while (f && !ch[f][c]) ch[f][c] = p, f = fa[f];
    if (!f) {
      fa[p] = 1;
      return;
    }
    int x = ch[f][c], y = ++gt;
    if (len[x] == len[f] + 1) {
      fa[p] = x;
      gt--;
      return;
    }
    len[y] = len[f] + 1;
    fa[y] = fa[x];
    fa[x] = fa[p] = y;
    for (int i = 0; i < M; i++) ch[y][i] = ch[x][i];
    while (f && ch[f][c] == x) ch[f][c] = y, f = fa[f];
  }
} g;
bool cmp(const int &a, const int &b) { return t.id[a] < t.id[b]; }
int ov1[N], ov2[N], d1[N], d2[N], sta[N], p;
vector<int> e1[N];
void ins(int x) {
  if (p == 1) {
    sta[++p] = x;
    return;
  }
  int lc = t.lca(sta[p], x);
  if (lc == sta[p]) {
    sta[++p] = x;
    return;
  }
  while (p > 1 && t.id[sta[p - 1]] >= t.id[lc])
    e1[sta[p - 1]].push_back(sta[p]), p--;
  if (lc != sta[p]) e1[lc].push_back(sta[p]), sta[p] = lc;
  sta[++p] = x;
}
void ins2(int x) {
  if (!p) {
    sta[++p] = x;
    return;
  }
  int lc = t.lca(x, sta[p]);
  while (t.id[lc] < t.id[sta[p]]) {
    if (t.id[lc] >= t.id[sta[p - 1]]) {
      e1[lc].push_back(sta[p--]);
      if (lc != sta[p]) sta[++p] = lc;
      break;
    } else
      e1[sta[p - 1]].push_back(sta[p]), p--;
  }
  sta[++p] = x;
}
void dfs3(int u) {
  d1[u] = ov1[u];
  d2[u] = ov2[u];
  ans += 1ll * d1[u] * d2[u] * g.len[u];
  for (int i = 0; i < (int)e1[u].size(); i++) {
    int v = e1[u][i];
    dfs3(v);
    ans += 1ll * (1ll * d1[u] * d2[v] + 1ll * d2[u] * d1[v]) * g.len[u];
    d1[u] += d1[v];
    d2[u] += d2[v];
  }
  e1[u].clear();
  ov1[u] = ov2[u] = 0;
}
void bdt() {
  p = 0;
  sort(q + 1, q + 1 + ind, cmp);
  for (int i = 1; i <= k; i++) ov1[pos[a[i]]] = 1;
  for (int i = 1; i <= l; i++) ov2[pos[b[i]]] = 1;
  for (int i = 1; i <= ind; i++) ins2(q[i]);
  while (p > 1) e1[sta[p - 1]].push_back(sta[p]), p--;
  dfs3(sta[1]);
  for (int i = 1; i <= ind; i++) d1[q[i]] = d2[q[i]] = 0;
}
int main() {
  g.init();
  t.init();
  scanf("%d%d%s", &n, &m, s + 1);
  reverse(s + 1, s + 1 + n);
  for (int i = 1; i <= n; i++) g.ins(s[i] - 'a'), pos[i] = g.lst;
  for (int i = 2; i <= g.gt; i++) t.add(g.fa[i], i);
  t.mkrt(1);
  while (m--) {
    scanf("%d%d", &k, &l);
    tot = 0;
    ans = 0;
    for (int i = 1; i <= k; i++)
      scanf("%d", &a[i]), a[i] = n - a[i] + 1, q[++tot] = pos[a[i]];
    for (int i = 1; i <= l; i++)
      scanf("%d", &b[i]), b[i] = n - b[i] + 1, q[++tot] = pos[b[i]];
    sort(q + 1, q + 1 + tot);
    ind = unique(q + 1, q + 1 + tot) - q - 1;
    bdt();
    printf("%lld\n", ans);
  }
  return 0;
}
