You are given a string $$$s$$$ of size $$$n$$$ consisting of lowercase English alphabets $$$(a \space to \space z)$$$. The cost of moving from a character $$$c_i$$$ at index $$$i$$$ to $$$c_j$$$ at index $$$j$$$ is as follows:
You are given $$$q$$$ queries. Each query is of the form : $$$u \space v$$$
where you need to find minimum cost to move from character $$$u$$$ (i.e any index i such that $$$c_i = u$$$) to character $$$v$$$ (i.e any index j such that $$$c_j = v$$$). Print $$$-1$$$ if it's not possible to reach from $$$u$$$ to $$$v$$$(If any of u or v does not exist in string, then print $$$-1$$$).
First line contains $$$n$$$ and $$$q$$$. $$$(1 \leq n \leq 10^5)$$$ $$$(1 \leq q \leq 26 \times 26)$$$
Next line contains string $$$s$$$.
Next $$$q$$$ lines contain: $$$u \space v$$$ $$$(a \leq u, v \leq z)$$$
For each query output minimum cost to move from character $$$u$$$ to character $$$v$$$.
9 2aabbcedbaa cb d
2 1
11 7dcdcccedcebe bd be eb ee aa bd d
1 2 0 1 -1 -1 0
In test case $$$1$$$, we can move from 'a' at index $$$1$$$ to 'b' at index $$$2$$$ in cost of $$$|2-1|=1$$$. Now we can move from 'b' at index $$$2$$$ to 'b' at index $$$3$$$ in cost of $$$0$$$. Now we can reach 'c' at index $$$4$$$ from 'b' at index $$$3$$$ in cost of $$$|3-2|=1$$$. Thus the minimum cost of moving from 'a' to 'c' comes out to be $$$2$$$.