#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, k, l, q;
int a[N], b[N], c[2 * N], sa[N], rnk[N], lcp[N], s[N];
long long lm[2 * N], rm[2 * N], t[4 * N];
string S;
void build(int id, int x, int y) {
  if (x == y) {
    t[id] = lcp[x];
    return;
  }
  int mid = (x + y) >> 1;
  build(2 * id, x, mid);
  build(2 * id + 1, mid + 1, y);
  t[id] = min(t[2 * id], t[2 * id + 1]);
}
int get_lcp(int l, int r, int id = 1, int x = 0, int y = n - 2) {
  if (l > y or r < x) return N;
  if (l <= x and r >= y) return t[id];
  int mid = (x + y) >> 1;
  return min(get_lcp(l, r, 2 * id, x, mid),
             get_lcp(l, r, 2 * id + 1, mid + 1, y));
}
void kasai() {
  int k = 0;
  for (int i = 0; i < n; i++) rnk[sa[i]] = i;
  for (int i = 0; i < n; i++, k ? k-- : 0) {
    if (rnk[i] == n - 1) {
      k = 0;
      continue;
    }
    int j = sa[rnk[i] + 1];
    while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;
    lcp[rnk[i]] = k;
  }
  build(1, 0, n - 2);
}
inline bool leq(int a1, int a2, int b1, int b2) {
  return (a1 < b1 || a1 == b1 && a2 <= b2);
}
inline bool leq(int a1, int a2, int a3, int b1, int b2, int b3) {
  return (a1 < b1 || a1 == b1 && leq(a2, a3, b2, b3));
}
static void radixPass(int* a, int* b, int* r, int n, int K) {
  int* c = new int[K + 1];
  for (int i = 0; i <= K; i++) c[i] = 0;
  for (int i = 0; i < n; i++) c[r[a[i]]]++;
  for (int i = 0, sum = 0; i <= K; i++) {
    int t = c[i];
    c[i] = sum;
    sum += t;
  }
  for (int i = 0; i < n; i++) b[c[r[a[i]]]++] = a[i];
  delete[] c;
}
void suffixArray(int* s, int* SA, int n, int K) {
  int n0 = (n + 2) / 3, n1 = (n + 1) / 3, n2 = n / 3, n02 = n0 + n2;
  int* s12 = new int[n02 + 3];
  s12[n02] = s12[n02 + 1] = s12[n02 + 2] = 0;
  int* SA12 = new int[n02 + 3];
  SA12[n02] = SA12[n02 + 1] = SA12[n02 + 2] = 0;
  int* s0 = new int[n0];
  int* SA0 = new int[n0];
  for (int i = 0, j = 0; i < n + (n0 - n1); i++)
    if (i % 3 != 0) s12[j++] = i;
  radixPass(s12, SA12, s + 2, n02, K);
  radixPass(SA12, s12, s + 1, n02, K);
  radixPass(s12, SA12, s, n02, K);
  int name = 0, c0 = -1, c1 = -1, c2 = -1;
  for (int i = 0; i < n02; i++) {
    if (s[SA12[i]] != c0 || s[SA12[i] + 1] != c1 || s[SA12[i] + 2] != c2) {
      name++;
      c0 = s[SA12[i]];
      c1 = s[SA12[i] + 1];
      c2 = s[SA12[i] + 2];
    }
    if (SA12[i] % 3 == 1)
      s12[SA12[i] / 3] = name;
    else
      s12[SA12[i] / 3 + n0] = name;
  }
  if (name < n02) {
    suffixArray(s12, SA12, n02, name);
    for (int i = 0; i < n02; i++) s12[SA12[i]] = i + 1;
  } else
    for (int i = 0; i < n02; i++) SA12[s12[i] - 1] = i;
  for (int i = 0, j = 0; i < n02; i++)
    if (SA12[i] < n0) s0[j++] = 3 * SA12[i];
  radixPass(s0, SA0, s, n0, K);
  for (int p = 0, t = n0 - n1, k = 0; k < n; k++) {
    int i = (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2);
    int j = SA0[p];
    if (SA12[t] < n0 ? leq(s[i], s12[SA12[t] + n0], s[j], s12[j / 3])
                     : leq(s[i], s[i + 1], s12[SA12[t] - n0 + 1], s[j],
                           s[j + 1], s12[j / 3 + n0])) {
      SA[k] = i;
      t++;
      if (t == n02)
        for (k++; p < n0; p++, k++) SA[k] = SA0[p];
    } else {
      SA[k] = j;
      p++;
      if (p == n0)
        for (k++; t < n02; t++, k++)
          SA[k] = (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2);
    }
  }
  delete[] s12;
  delete[] SA12;
  delete[] SA0;
  delete[] s0;
}
long long solve(int* a, int m) {
  for (long long i = 1; i < m; i++) {
    if (a[i] == a[i + 1])
      a[i] = n - sa[a[i]];
    else
      a[i] = get_lcp(a[i], a[i + 1] - 1);
  }
  m--;
  stack<long long> s;
  while (!s.empty()) s.pop();
  for (long long i = 1; i <= m; i++) {
    while (!s.empty() and a[s.top()] > a[i]) {
      rm[s.top()] = i;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) {
    rm[s.top()] = m + 1;
    s.pop();
  }
  for (long long i = m; i > 0; i--) {
    while (!s.empty() and a[s.top()] >= a[i]) {
      lm[s.top()] = i;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) {
    lm[s.top()] = 0;
    s.pop();
  }
  long long ans = 0;
  for (long long i = 1; i <= m; i++) {
    ans += 1ll * a[i] * (i - lm[i]) * (rm[i] - i);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> q;
  cin >> S;
  if (n == 1) {
    while (q--) {
      cin >> k >> l;
      cout << 1ll * k * l << endl;
      cin >> k >> l;
    }
    return 0;
  }
  for (int i = 0; i < n; i++) s[i] = S[i] - 'a' + 1;
  suffixArray(s, sa, n, 26);
  kasai();
  while (q--) {
    cin >> k >> l;
    for (long long i = 1; i <= k; i++) {
      cin >> a[i];
      a[i] = rnk[a[i] - 1];
      c[i] = a[i];
    }
    for (long long i = 1; i <= l; i++) {
      cin >> b[i];
      b[i] = rnk[b[i] - 1];
      c[i + k] = b[i];
    }
    sort(a + 1, a + k + 1);
    sort(b + 1, b + l + 1);
    sort(c + 1, c + k + l + 1);
    long long ans = solve(c, k + l) - solve(a, k) - solve(b, l);
    cout << ans << endl;
  }
}
