Given a **string** you have to answer several queries on that string. In each query you will be provided two values **L** and **R** and you have to find the number of **distinct** characters in the sub string from index **L** to index **R** (inclusive) of the original string.

**Input **

The first line of the input contains **T**, the number of test cases. Then **T** test cases follow. Each test case consists of 3 lines. The first line contains the string **S**. The second line contains the value of **Q**, the number of queries. The next line contains **2*Q** integers describing the queries in the form **L1 R1 L2 R2…..LQ RQ**.

**Output**

For each test case output the answer of the queries in a single line separated by a space. The answer of different test cases should appear on separate lines.

**Constraints : **

1<=**T**<=10

1<=**|S|**<=10000

1<=**Q**<=10000

1<=**L**<=**R**<=**|S|**

The string consists of only lower case English letters. (**a-z**)

**Example **

**Input**

1

abcbaed

3

1 4 2 4 1 7

**Output **

3 2 5

**Explanation **

Above there is only one test case having 3 queries

1. In the first query we see that in the interval (1,4) the distinct letters are a,b,c so answer is 3.

2. In the second query we see that in the interval (2,4) the distinct letters are b,c.

3. In the third query we see that in the interval (1,7) the distinct letters are a,b,c,d,e so answer is 5.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

hardikJain5 | 258 |

CodeBuddy | 250 |

bhatabhi554 | 232 |

Akkki111 | 197 |

clone | 174 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1127 |

mazumderrohit8 | 1124 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4591 |

Quandray | 4444 |

Login to report an issue on this page.