#include <bits/stdc++.h>
using namespace std;
int main() {
int n,q; cin >> n >> q;
string s; cin >> s;
int l,r;
for(int i = 0; i < n; i++) { // first food position
if(s[i] == 'F') {
l = i;
break;
}
}
for(int i = n-1; i >= 0; i--) { // last food position
if(s[i] == 'F') {
r = i;
break;
}
}
int dirt = 0, food = 0;
for(int i = l; i <= r; i++) {
if(s[i] == 'D') dirt++;
if(s[i] == 'F') food++;
}
int mid = food/2 + food % 2; // it is always optimal to gather the food around the median
int cnt = 0, idx;
for(int i = l; i <= r; i++) {
if(s[i] == 'F') cnt++;
if(cnt == mid) {
idx = i;
break;
}
}
//before mid
int prev = 0, shift = 0;
cnt = 0;
for(int i = l; i < idx; i++) {
if(s[i] == 'F') cnt++;
else prev += cnt;
}
// after mid
cnt = 0, shift = prev, prev = 0;
for(int i = r; i >= idx; i--) {
if(s[i] == 'F') cnt++;
else prev += cnt;
}
shift += prev;
while(q--) {
int x,y; cin >> x >> y; // x -> shifting food to adjacent , y -> cleaning the dirt
cout << (dirt*y) + (shift*x) << "\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCBuLHE7IGNpbiA+PiBuID4+IHE7CglzdHJpbmcgczsgY2luID4+IHM7CglpbnQgbCxyOwoJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgeyAgLy8gZmlyc3QgZm9vZCBwb3NpdGlvbgoJCWlmKHNbaV0gPT0gJ0YnKSB7CgkJCWwgPSBpOwoJCQlicmVhazsKCQl9Cgl9CgkKCWZvcihpbnQgaSA9IG4tMTsgaSA+PSAwOyBpLS0pIHsgIC8vIGxhc3QgZm9vZCBwb3NpdGlvbgoJCWlmKHNbaV0gPT0gJ0YnKSB7CgkJCXIgPSBpOwoJCQlicmVhazsKCQl9Cgl9CgkKCWludCBkaXJ0ID0gMCwgZm9vZCA9IDA7Cglmb3IoaW50IGkgPSBsOyBpIDw9IHI7IGkrK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