class Solution:
    def toGoatLatin(self, S):
        """
        :type S: str
        :rtype: str
        """
        res = []
        for i, word in enumerate(S.split()):
            w = list(word)
            if w[0] not in 'AEIOUaeiou':
                w.append(w[0])
                w[0] = ''
            w.append('ma')
            w.append('a' * (i+1))
            res.append(''.join(w))
        return ' '.join(res)