import email.utils as em
import re

class Main():
    def __init__(self):
        self.n = int(input())
        
        for i in range(self.n):
            self.s = em.parseaddr(input())
            
            if re.match(r'^[a-zA-Z](\w|-|\.|_)+@[a-zA-Z]+\.[a-zA-Z]{0,3}$', self.s[1]):
                print(em.formataddr(self.s))
        
if __name__ == '__main__':
    obj = Main()

[(11, 're.match', 're.match', False, 'import re\n'), (12, 'email.utils.formataddr', 'em.formataddr', True, 'import email.utils as em\n')]