function main(input = "") {
    let grid = toGrid32(input);
    let c = grid[1];
    let res = "";

    for (let i = 2; i < grid.length; i++) {
        let l = grid[i][0] - 1;
        let r = grid[i][1] - 1;
        let s = new Set(c.slice(l, r + 1));
        res += s.size + "\n";
    }
    return res.trim();
}

function toGrid32(input = "") {
    return input.split("\n").map((v) => new Int32Array(v.split(" ")));
}

//******************************
exports.main = main;

function Main(input) {
    console.log(main(input.trim()));
}

if (process.argv[2] !== "test") {
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}