Deep within the Halzoom's labyrinth, the three discovered an ancient, magical scroll, its text constantly shifting and rearranging itself. This was the Echoing Scroll of Fate, said to reveal the future, but only if its patterns were understood.
The scroll contained a long, secret message, a string of mystical characters. At various times, a whisper from the Unknown would activate a specific part of the scroll, a substring from index $$$L$$$ to $$$R$$$. For each such activation, a strange task appeared:
Find the Shortest Echo Cycle: They had to determine the minimum period of the characters in that specific part of the scroll $$$(S[L \cdots R])$$$. A period of a string is a prefix that can be used to generate the whole string by repeating the prefix. For example, the string "abcabcabc" has a length of $$$9$$$, but its minimum period is $$$3$$$ (because "abc" repeats). The minimum period of "ababab" is $$$2$$$.
Check the Scroll's Memory: They then had to recall if this exact minimum period had ever appeared as a minimum period from any previous query on this scroll.
Whisper of Reversal:
Abd-Elmohaymen, feeling the magical energy of the scroll, sensed that mastering its shifts was crucial for charting their destiny in this dream.
Your task is to help them manage the Echoing Scroll of Fate. After all queries, you must tell them what the new scroll is.
The first line contains two integers $$$N(1 \le N \le 10^5)$$$, the length of the scroll , $$$Q$$$ ($$$1 \le Q \le 10^5 $$$), the number of activations (queries), and a string $$$S$$$ of length $$$N$$$ consisting of lowercase English letters, representing the initial contents of the scroll.
The next $$$Q$$$ lines each contain two integers $$$L,R$$$ ($$$1 \le L \le R \le N$$$), representing the start and end of the substring for the current query.
You must print the new scroll after all queries.
9 3abcabcabc1 93 72 4
cacbbcaba
9 3jxngmvzku3 56 81 4
gmxjnkzvu