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, 15, 11, 86), 're.match', 're.match', ({(11, 24, 11, 74): '"""^[a-zA-Z](\\\\w|-|\\\\.|_)+@[a-zA-Z]+\\\\.[a-zA-Z]{0,3}$"""', (11, 76, 11, 85): 'self.s[1]'}, {}), "('^[a-zA-Z](\\\\w|-|\\\\.|_)+@[a-zA-Z]+\\\\.[a-zA-Z]{0,3}$', self.s[1])", False, 'import re\n'), ((12, 22, 12, 43), 'email.utils.formataddr', 'em.formataddr', ({(12, 36, 12, 42): 'self.s'}, {}), '(self.s)', True, 'import email.utils as em\n')]