Write a function that, given a string S consisting of N characters, returns any string that can result from a sequence of transformations