#include <bits/stdc++.h>
using namespace std;
namespace IO {
char buf[1 << 21], *p1 = buf, *p2 = buf, buf1[1 << 21];
inline char gc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <class I>
inline void read(I &x) {
  x = 0;
  I f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class I>
inline void write(I x) {
  if (x == 0) {
    putchar('0');
    return;
  }
  I tmp = x > 0 ? x : -x;
  if (x < 0) putchar('-');
  long long cnt = 0;
  while (tmp > 0) {
    buf1[cnt++] = tmp % 10 + '0';
    tmp /= 10;
  }
  while (cnt > 0) putchar(buf1[--cnt]);
}
}  // namespace IO
using namespace IO;
long long n, q;
char s[500010];
long long Matrix[500010][50];
namespace DS {
class Suf_arr {
 private:
  long long x[500010], y[500010];
  long long bu[500010];

 public:
  long long sa[500010], rk[500010];
  long long ht[500010];
  void debug() {
    for (long long i = 1; i <= n; i++) {
      write(sa[i]), putchar(' ');
    }
    puts("");
    for (long long i = 1; i <= n; i++) {
      write(rk[i]), putchar(' ');
    }
    puts("");
    for (long long i = 1; i <= n; i++) {
      write(ht[i]), putchar(' ');
    }
    puts("");
  }
  void get_sa(char *s) {
    long long m = (1 << 7) + 1;
    for (long long i = 1; i <= n; i++) {
      x[i] = s[i - 1];
      ++bu[x[i]];
    }
    for (long long i = 1; i <= m; i++) {
      bu[i] += bu[i - 1];
    }
    for (long long i = n; i >= 1; i--) {
      sa[bu[x[i]]--] = i;
    }
    for (long long k = 1; k <= n; k <<= 1) {
      long long num_cnt = 0;
      for (long long i = n - k + 1; i <= n; i++) {
        y[++num_cnt] = i;
      }
      for (long long i = 1; i <= n; i++) {
        if (sa[i] > k) {
          y[++num_cnt] = sa[i] - k;
        }
      }
      for (long long i = 1; i <= m; i++) {
        bu[i] = 0;
      }
      for (long long i = 1; i <= n; i++) {
        ++bu[x[i]];
      }
      for (long long i = 1; i <= m; i++) {
        bu[i] += bu[i - 1];
      }
      for (long long i = n; i >= 1; i--) {
        sa[bu[x[y[i]]]--] = y[i];
        y[i] = 0;
      }
      std::swap(x, y);
      num_cnt = 1;
      x[sa[1]] = 1;
      for (long long i = 2; i <= n; i++) {
        if (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]) {
          x[sa[i]] = num_cnt;
        } else {
          x[sa[i]] = ++num_cnt;
        }
      }
      if (num_cnt == n) {
        break;
      }
      m = num_cnt;
    }
  }
  void get_ht(char *s) {
    long long len = strlen(s), k = 0;
    for (long long i = 1; i <= len; i++) {
      rk[sa[i]] = i;
    }
    for (long long i = 1; i <= len; i++) {
      if (rk[i] == 1) {
        continue;
      }
      if (k) {
        --k;
      }
      long long pos = sa[rk[i] - 1];
      while (pos + k <= len && i + k <= len && s[pos + k - 1] == s[i + k - 1]) {
        ++k;
      }
      ht[rk[i]] = k;
    }
  }
} sa;
}  // namespace DS
using namespace DS;
long long lg[500010];
void init() {
  read(n), read(q);
  std::cin >> s;
  long long len = strlen(s);
  sa.get_sa(s);
  sa.get_ht(s);
  lg[0] = 0;
  for (long long i = 1; i <= n; i++) {
    lg[i] = lg[i - 1] + (1 << lg[i - 1] + 1 == i);
  }
  for (long long i = 1; i <= len; i++) {
    Matrix[i][0] = sa.ht[i];
  }
  for (long long j = 1; 1 << j <= len; j++) {
    for (long long i = 1; i + (1 << j) - 1 <= n; i++) {
      Matrix[i][j] =
          std::min(Matrix[i][j - 1], Matrix[i + (1 << (j - 1))][j - 1]);
    }
  }
}
long long rmq(long long l, long long r) {
  long long k = lg[r - l + 1];
  return std::min(Matrix[l][k], Matrix[r - (1 << k) + 1][k]);
}
long long lcp(long long l, long long r) {
  if (l == r) {
    return n - l + 1;
  }
  if (sa.rk[l] > sa.rk[r]) {
    std::swap(l, r);
  }
  return rmq(sa.rk[l] + 1, sa.rk[r]);
}
long long len_1, len_2;
long long a[500010], b[500010], c[500010];
long long key[500010];
long long sum[500010];
struct sta {
  long long first;
  long long second;
} Sta[500010];
void update(long long &ans, long long i, long long top) {
  ans += (1ll * (sum[Sta[top].first - 1] - sum[Sta[top].second - 2]) *
              ((i - Sta[top].first) - (sum[i - 1] - sum[Sta[top].first - 1])) +
          1ll *
              ((Sta[top].first - Sta[top].second + 1) -
               (sum[Sta[top].first - 1] - sum[Sta[top].second - 2])) *
              (sum[i - 1] - sum[Sta[top].first - 1])) *
         lcp(c[Sta[top].first], c[Sta[top].first - 1]);
  return;
  ans += (1ll * (sum[Sta[top].first - 1] - sum[Sta[top].second - 2]) *
              ((i - Sta[top].first) - (sum[i - 1] - sum[Sta[top].first - 1])) +
          1ll *
              ((Sta[top].first - Sta[top].second + 1) -
               (sum[Sta[top].first - 1] - sum[Sta[top].second - 2])) *
              (sum[i - 1] - sum[Sta[top].first - 1])) *
         lcp(c[Sta[top].first], c[Sta[top].first - 1]);
}
void tab() {
  long long times = 5;
  while (times--) {
    printf("\t");
  }
}
bool cmp(long long a, long long b) { return sa.rk[a] < sa.rk[b]; }
signed main() {
  init();
  while (q--) {
    read(len_1), read(len_2);
    for (long long i = 1; i <= len_1; i++) {
      read(a[i]);
    }
    for (long long i = 1; i <= len_2; i++) {
      read(b[i]);
    }
    std::sort(a + 1, a + len_1 + 1,
              [&](long long a, long long b) { return sa.rk[a] < sa.rk[b]; });
    std::sort(b + 1, b + len_2 + 1,
              [&](long long a, long long b) { return sa.rk[a] < sa.rk[b]; });
    for (long long i = 1, j = 1, t = 1; i <= len_1 || j <= len_2; t++) {
      if (i <= len_1 && (j > len_2 || sa.rk[a[i]] <= sa.rk[b[j]])) {
        c[t] = a[i++];
        key[t] = 0;
      } else if (j <= len_2 && (i > len_1 || sa.rk[a[i]] > sa.rk[b[j]])) {
        c[t] = b[j++];
        key[t] = 1;
      }
    }
    long long ans = 0;
    sum[0] = 0;
    long long top = 0;
    for (long long i = 1; i <= len_1 + len_2; i++) {
      sum[i] = sum[i - 1] + key[i];
    }
    for (long long i = 1; i <= len_1 + len_2; i++) {
      long long now = i;
      while (top > 0 && lcp(c[i], c[i - 1]) < lcp(c[Sta[top - 1].first],
                                                  c[Sta[top - 1].first - 1])) {
        now = std::min(now, Sta[--top].second);
        update(ans, i, top);
      }
      Sta[top++] = (sta){i, now};
    }
    while (top > 0) {
      --top;
      update(ans, len_1 + len_2 + 1, top);
    }
    write(ans), putchar('\n');
  }
  return 0;
}
