def rewrite(text, initial=(), hide=(), upper=()):
    initial = frozenset(initial)
    hide = frozenset(hide)
    upper = frozenset(upper)
        
    content = text.split()
    new_content = []
    for word in content:
        if word in upper:
            new_content.append(word.upper())
        elif word in hide:
            new_content.append('*' * len(word))
        elif word in initial:
            new_content.append(word[0] + '*' * (len(word) - 1))
        else:
            new_content.append(word)

    return ' '.join(new_content)
    
text = 'Python rocks but Java sucks'

print(rewrite(text, initial=['sucks'], hide=['Java'], upper=['Python']))
print(rewrite(text, initial=['sucks'], upper=['Python']))
