fix the management in case of q bigger than the length of the string