"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

!function () {
  function splitNum(line) {
    return (Array.isArray(line) ? line : line.split(/\s+/)).map(function (n) {
      return parseInt(n);
    });
  }

  function* range(start, end) {
    for (var i = start; i < end; i++) {
      yield i;
    }
  }

  (function () {
    var Longer =
    /*#__PURE__*/
    function () {
      function Longer(value) {
        _classCallCheck(this, Longer);

        this.data = [0, 0, 0];
        var idx = 0;

        for (; 0 !== value;) {
          this.data[idx] = value % Longer.border;
          value = Math.floor(value / Longer.border);
          idx++;
        }
      }

      _createClass(Longer, [{
        key: "add",
        value: function add(right) {
          var result = new Longer(0);
          var max = Math.max(this.data.length, right.data.length);
          var carry = 0;
          var idx = 0;

          for (; idx < max; idx++) {
            var sum = (this.data[idx] || 0) + (right.data[idx] || 0) + carry;
            result.data[idx] = sum % Longer.border;
            carry = Math.floor(sum / Longer.border);
          }

          if (carry > 0) result.data[idx] = carry;
          return result;
        }
      }, {
        key: "mul",
        value: function mul(right) {
          var result = new Longer(0);

          for (var lidx = 0; lidx < this.data.length; lidx++) {
            for (var ridx = 0; ridx < right.data.length; ridx++) {
              var tidx = lidx + ridx;
              var value = this.data[lidx] * right.data[ridx];

              for (; value > 0;) {
                var sum = (result.data[tidx] || 0) + value;
                result.data[tidx] = sum % Longer.border;
                value = Math.floor(sum / Longer.border);
                tidx++;
              }
            }
          }

          return result;
        }
      }, {
        key: "toString",
        value: function toString() {
          var d = this.data.concat().reverse();

          var fsti = function (arr, pred) {
            for (var i = 0; i < arr.length; i++) {
              if (pred(arr[i], i)) return i;
            }

            return null;
          }(d, function (v) {
            return 0 !== v;
          });

          if (null == fsti) return "0";else return d.slice(fsti).map(function (v, i) {
            if (0 === i) return String(v);else return padStart(String(v), Longer.digits, "0");
          }).join("");

          function padStart(str, num, pad) {
            var n = num - str.length;
            var result = "";

            for (var i = 0; i < n; i++) {
              result += pad;
            }

            return result + str;
          }
        }
      }]);

      return Longer;
    }();

    Longer.digits = 7;
    Longer.border = Math.pow(10, Longer.digits);
  })();

  !function (input) {
    var lines = input.split("\n");

    var _splitNum = splitNum(lines[0]),
        _splitNum2 = _slicedToArray(_splitNum, 2),
        N = _splitNum2[0],
        Q = _splitNum2[1];

    var S = lines[1].slice(0, N);
    var acc = [];
    var sum = 0;
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = range(0, N)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var i = _step.value;
        if ("A" === S[i] && "C" === S[i + 1]) sum++;
        acc[i] = sum;
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    var lrs = lines.slice(2, Q + 2).map(function (line) {
      var _splitNum3 = splitNum(line),
          _splitNum4 = _slicedToArray(_splitNum3, 2),
          l = _splitNum4[0],
          r = _splitNum4[1];

      return {
        l: l,
        r: r
      };
    });
    var _iteratorNormalCompletion2 = true;
    var _didIteratorError2 = false;
    var _iteratorError2 = undefined;

    try {
      for (var _iterator2 = lrs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
        var _step2$value = _step2.value,
            l = _step2$value.l,
            r = _step2$value.r;
        var ac = acc[r - 1 - 1] - (1 === l ? 0 : acc[l - 1 - 1]);
        console.log(ac);
      }
    } catch (err) {
      _didIteratorError2 = true;
      _iteratorError2 = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
          _iterator2.return();
        }
      } finally {
        if (_didIteratorError2) {
          throw _iteratorError2;
        }
      }
    }
  }(require("fs").readFileSync("/dev/stdin", "utf8"));
}();
