#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int arr = 2e5 + 10;
const int ar = 2e3 + 10;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long md = 1e9 + 7;
int n, q;
string s;
unsigned long long pp[(int)(1e6 + 10)];
unsigned long long h[(int)(1e6 + 10)];
unsigned long long magic(int a, int b) {
  return (a + 1) * b % (a == 1 ? 1 : a - 1) ^ 124 + a * b + a + b * 1000ul + a ^
         b + a ^ (b * 12442ull) + a * a ^
         (b % 124564ull) + a % (b == 0 ? 1 : b) + b % (a == 0 ? 1 : a) +
             b * a % (b % a == 0 ? 1 : b % a);
}
unsigned long long get_hash(int l, int r) {
  if (l == r) {
    return s[l];
  }
  unsigned long long res = h[r];
  res -= h[l];
  res *= pp[(int)(1e6 + 10) - l - 1];
  return res;
}
bool eq(int l1, int r1, int l2, int r2) {
  return r1 - l1 == r2 - l2 && s[l1] == s[l2] &&
         get_hash(l1, r1) == get_hash(l2, r2);
}
int lcp(int i, int j) {
  int l = 0, r = (int)(s.size()) - max(i, j);
  while (r - l > 0) {
    int m = (l + r + 1) / 2;
    if (eq(i, i + m - 1, j, j + m - 1)) {
      l = m;
    } else {
      r = m - 1;
    }
  }
  return l;
}
bool cmp(int i, int j) {
  int l = lcp(i, j);
  if (i + l - 1 == (int)(s.size()) - 1 || j + l - 1 == (int)(s.size()) - 1) {
    return i > j;
  }
  return s[i + l] < s[j + l];
}
int p[(int)(1e6 + 10)];
int lpc[(int)(1e6 + 10)];
const int M = 20;
int lg[(int)(1e6 + 10)];
int stb[(int)(1e6 + 10)][M];
int get_min(int l, int r) {
  int k = lg[r - l + 1];
  return min(stb[l][k], stb[r - (1ll << k) + 1][k]);
}
int L[(int)(1e6 + 10)];
int R[(int)(1e6 + 10)];
unsigned long long get_sum_min(vector<int> v) {
  vector<pair<int, int>> s;
  s.clear();
  for (int i = 0; i < (int)(v.size()); i++) {
    while (!s.empty() && s.back().first > v[i]) {
      s.pop_back();
    }
    if (s.empty()) {
      L[i] = -1;
    } else {
      L[i] = s.back().second;
    }
    s.push_back(make_pair(v[i], i));
  }
  s.clear();
  for (int i = (int)(v.size()) - 1; i >= 0; i--) {
    while (!s.empty() && s.back().first >= v[i]) {
      s.pop_back();
    }
    if (s.empty()) {
      R[i] = (int)(v.size());
    } else {
      R[i] = s.back().second;
    }
    s.push_back(make_pair(v[i], i));
  }
  unsigned long long res = 0;
  for (int i = 0; i < (int)(v.size()); i++) {
    res += 1ull * (i - L[i]) * (R[i] - i) * v[i];
  }
  return res;
}
int rp[(int)(1e6 + 10)];
unsigned long long get(vector<int> a) {
  for (auto &i : a) {
    i = rp[i];
  }
  sort(a.begin(), a.end());
  vector<int> v(0);
  for (int i = 0; i + 1 < (int)(a.size()); i++) {
    if (a[i] == a[i + 1]) {
      v.push_back((int)(s.size()) - p[a[i]]);
    } else {
      v.push_back(get_min(a[i], a[i + 1] - 1));
    }
  }
  return get_sum_min(v);
}
int class_eq[(int)(1e6 + 10)];
vector<pair<int, int>> vh[(int)(1e6 + 10)];
vector<int> vh1[(int)(1e6 + 10)];
bool cmp_magic(int i, int j) { return class_eq[i] < class_eq[j]; }
vector<pair<pair<int, int>, int>> vh_sort[(int)(1e6 + 10)];
void build_p() {
  s = s + "#";
  n++;
  for (int i = 0; i < n; i++) {
    class_eq[i] = s[i];
  }
  for (int j = 1; j < M; j++) {
    vector<pair<pair<int, int>, int>> v(0);
    for (int i = 0; i < n; i++) {
      v.push_back(make_pair(
          make_pair(class_eq[i], class_eq[(i + (1ll << (j - 1))) % n]), i));
    }
    int max_class_eq = *max_element(class_eq, class_eq + n);
    for (int i = 0; i <= max_class_eq; i++) {
      vh_sort[i].clear();
    }
    for (auto i : v) {
      int val = i.first.second;
      vh_sort[val].push_back(i);
    }
    v.clear();
    for (int i = 0; i <= max_class_eq; i++) {
      for (auto j : vh_sort[i]) {
        v.push_back(j);
      }
    }
    for (int i = 0; i <= max_class_eq; i++) {
      vh_sort[i].clear();
    }
    for (auto i : v) {
      int val = i.first.first;
      vh_sort[val].push_back(i);
    }
    v.clear();
    for (int i = 0; i <= max_class_eq; i++) {
      for (auto j : vh_sort[i]) {
        v.push_back(j);
      }
    }
    int last = 0;
    for (int i = 0; i < n; i++) {
      if (i == 0 || v[i].first != v[i - 1].first) {
        class_eq[v[i].second] = last++;
      } else {
        class_eq[v[i].second] = class_eq[v[i - 1].second];
      }
    }
  }
  n--;
  s.pop_back();
  sort(p, p + n, cmp_magic);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = 2; i < (int)(1e6 + 10); i++) {
    lg[i] = lg[i / 2] + 1;
  }
  pp[0] = 1;
  for (int i = 1; i < (int)(1e6 + 10); i++) {
    pp[i] = pp[i - 1] * 12425ull;
  }
  cin >> n >> q;
  cin >> s;
  h[0] = 0;
  for (int i = 1; i < n; i++) {
    h[i] = h[i - 1] + pp[i] * magic(s[i - 1], s[i]);
  }
  for (int i = 0; i < n; i++) {
    p[i] = i;
  }
  build_p();
  for (int i = 0; i < n; i++) {
    rp[p[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    lpc[i - 1] = lcp(p[i - 1], p[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    stb[i][0] = lpc[i];
  }
  for (int j = 1; j < M; j++) {
    for (int i = 0; i + (1ll << j) - 1 < n - 1; i++) {
      stb[i][j] = min(stb[i][j - 1], stb[i + (1ll << (j - 1))][j - 1]);
    }
  }
  while (q--) {
    int s1, s2;
    cin >> s1 >> s2;
    vector<int> ab(0);
    vector<int> a(0);
    vector<int> b(0);
    while (s1--) {
      int x;
      cin >> x;
      x--;
      a.push_back(x);
      ab.push_back(x);
    }
    while (s2--) {
      int x;
      cin >> x;
      x--;
      b.push_back(x);
      ab.push_back(x);
    }
    cout << get(ab) - get(a) - get(b) << "\n";
  }
}
