#include using namespace std; const int maxn = 100005; int T, n, q; char s[maxn]; int pcnt[maxn][26]; int main() { scanf("%d", &T); for (int kase = 1; kase <= T; ++kase) { printf("Case #%d:\n", kase); scanf("%d%d", &n, &q); for (int i = 1; i <= n; ++i) for (int j = 0; j < 26; ++j) pcnt[i][j] = 0; scanf("%s", s + 1); for (int i = 1; i <= n; ++i) { for (int j = 0; j < 26; ++j) pcnt[i][j] = pcnt[i - 1][j]; ++pcnt[i][s[i] - 'A']; } while (q--) { int l, r; scanf("%d%d", &l, &r); for (int i = 0; i < 26; ++i) { int val = pcnt[r][i] - pcnt[l - 1][i]; if (val > 0) { printf("%d\n", val); break; } } } } return 0; }