A valid email address meets the following criteria:  

It's composed of a username, domain name, and extension assembled in this format: username@domain.extension 
The username starts with an English alphabetical character, and any subsequent characters consist of one or more of the following: alphanumeric characters, -,., and _.  
The domain and extension contain only English alphabetical characters.  
The extension is 1, 2, or 3 characters in length.

Given $n$ pairs of names and email addresses as input, print each name and email address pair having a valid email address on a new line.

Hint: Try using Email.utils() to complete this challenge. For example, this code: 

import email.utils
print email.utils.parseaddr('DOSHI <DOSHI@hackerrank.com>')
print email.utils.formataddr(('DOSHI', 'DOSHI@hackerrank.com'))

produces this output:

('DOSHI', 'DOSHI@hackerrank.com')
DOSHI <DOSHI@hackerrank.com>

Input Format

The first line contains a single integer, $n$, denoting the number of email address. 

Each line $\boldsymbol{i}$ of the $n$ subsequent lines contains a name and an email address as two space-separated values following this format:

name <user@email.com>

Constraints

$0<n<100$  

Output Format

Print the space-separated name and email address pairs containing valid email addresses only. Each pair must be printed on a new line in the following format:

name <user@email.com>

You must print each valid email address in the same order as it was received as input.

Sample Input
2  
DEXTER <dexter@hotmail.com>
VIRUS <virus!@variable.:p>

Sample Output
DEXTER <dexter@hotmail.com>

Explanation

dexter@hotmail.com is a valid email address, so we print the name and email address pair received as input on a new line. 

virus!@variable.:p is not a valid email address because the username contains an exclamation point (!) and the extension contains a colon (:). As this email is not valid, we print nothing.

Difficulty: EASY

Starter code:

Solutions:
import re
for _ in range(int(input())):
	(name, email) = input().split()
	if re.search('^<[a-zA-Z][\\w\\-\\.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>$', email):
		print(name, email)


import email.utils
import re
n = int(input())
for _ in range(n):
	line = input()
	(name, mail) = email.utils.parseaddr(line)
	if re.match('([a-zA-Z][a-zA-Z0-9._-]*)@([a-zA-Z]+)\\.([a-zA-Z]{1,3})$', mail):
		print(line)


import re
for t in range(int(input())):
	address = input()
	result = re.search('<[a-zA-Z0-9]+[\\w\\-,\\.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>', address)
	if result:
		print(address)


import re
for _ in range(int(input())):
	m = re.match('^([^ ]+) +<([a-zA-Z][\\w\\.-]+@[a-zA-Z]+\\.[a-zA-Z]{1,3})>$', input().strip())
	if m:
		print('%s <%s>' % (m.group(1), m.group(2)))


import email.utils, re
for _ in range(int(input())):
	m = email.utils.parseaddr(input())
	if re.match('^[a-z][\\w\\.-]*@[a-z]+\\.[a-z]{1,3}$', m[1], flags=re.I):
		print(email.utils.formataddr(m))


import re
from email.utils import parseaddr
n = int(input())
rule = re.compile('[a-zA-Z]{1}[\\w\\-.]*@[a-zA-Z]+[.]{1}[a-zA-Z]{1,3}$')
for _ in range(n):
	(username, email_addr) = parseaddr(input())
	m = rule.match(email_addr)
	if m:
		print('{} <{}>'.format(username, email_addr))


import re, email.utils
for _ in range(int(input())):
	p = email.utils.parseaddr(input())
	t = re.match('[a-zA-Z][\\w.-]*@[a-zA-Z]+\\.[a-zA-Z]{,3}$', p[1])
	if t:
		print(email.utils.formataddr(p))


import re
number_emails = int(input())
for _ in range(number_emails):
	name_and_email = input().strip()
	match = re.match('^<[a-zA-Z][\\w.-]+@[a-zA-Z]+\\.[a-zA-Z]{1,3}>$', name_and_email.split(' ', 1)[1])
	if match:
		print(name_and_email)


import re
for _ in range(int(input())):
	entry = input()
	print(entry) if re.match('^[a-zA-Z][a-zA-Z0-9_\\-\\.]+@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', entry.split()[1][1:-1]) else True


import re
N = int(input())
for i in range(N):
	a = input()
	if re.match('^[a-zA-Z]+ +<[a-z][\\w\\-._]*@[a-z]+\\.[a-z]{1,3}>', a):
		print(a)


import re
n = int(input())
p = '^(.+) <([a-z][\\w\\.\\-]*)@([a-z]+)\\.([a-z]{1,3})>$'
for _ in range(n):
	m = re.match(p, input().strip(), flags=re.I)
	if m:
		print(m.group())


import re
import email.utils
p = re.compile('^<[a-zA-Z]{1}[\\w_.-]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>$')
for _ in range(int(input())):
	(name, mail) = input().split()
	m = re.match(p, mail)
	if m is not None:
		print(name + ' ' + mail)


import re
regex = re.compile('<[a-zA-Z][a-zA-Z0-9-_\\.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>')
for _ in range(int(input())):
	(name, email) = input().strip().split()
	if regex.match(email):
		print(name, email)


import re
N = int(input())
result = re.compile('^[a-zA-Z]{1}[-\\w.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$')
for _ in range(N):
	ip = input().strip()
	email = ip.split()[1]
	if result.match(email[1:len(email) - 1]):
		print(ip)


import re
for _ in range(int(input())):
	m = re.match('([A-Za-z]+ <[A-Za-z]([A-Za-z0-9_-]|[.])*@[A-Za-z]+\\.[A-Za-z]{1,3}>)', input())
	if m:
		print(m.group(0))


def parse_emails(n):
	import re
	valid = []
	for _ in range(n):
		(name, check) = input().split()
		pattern = re.compile('<[a-z][a-z0-9._-]*@[a-z]+\\.[a-z]{1,3}>', re.IGNORECASE)
		if pattern.fullmatch(check):
			valid.append(name + ' ' + pattern.fullmatch(check).group())
	print('\n'.join(valid))
parse_emails(int(input()))


import re
n = int(input())
for ni in range(n):
	s = input()
	rgxuser = '^[A-Za-z][A-Za-z0-9-._]*$'
	rgxsite = '^[A-Za-z]*$'
	rgxext = '^[A-Za-z]{1,3}$'
	try:
		(n, email0) = s.split(' ')
		email = email0.strip()[1:-1]
		(user, r) = email.split('@')
		(site, ext) = r.split('.')
		m1 = re.match(rgxuser, user)
		m2 = re.match(rgxsite, site)
		m3 = re.match(rgxext, ext)
		if m1 and m2 and m3:
			print(s)
	except:
		pass


import re

def validEmail(line):
	email = re.findall('(?<=\\<)(.*)(?=\\>)', line)[0]
	return bool(re.match('^[a-zA-Z][-.\\w]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', email))
N = int(input())
print(*list(filter(validEmail, [input() for _ in range(N)])), sep='\n')


import re
for _ in range(int(input())):
	email = input()
	if re.fullmatch('<[a-zA-Z][a-zA-Z0-9-_\\.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>', email.split()[1]):
		print(email)


import re
from email.utils import parseaddr, formataddr
p = re.compile('^[a-zA-Z][\\w\\-\\.]*\\@[a-zA-Z]+\\.[a-zA-Z]{1,3}$')
N = int(input())
for _ in range(N):
	(name, email) = parseaddr(input())
	if p.match(email):
		print(formataddr((name, email)))


import re
for _ in range(int(input())):
	email = input().strip()
	if re.match('\\A<[a-z][a-z_.\\-0-9]*@[a-z]+\\.[a-z]{1,3}>\\Z', email.split(' ', 2)[1], re.IGNORECASE):
		print(email)


import re
import email.utils
t = int(input())
for i in range(0, t):
	s = input()
	e = email.utils.parseaddr(s)[1]
	if re.fullmatch('[a-zA-Z][\\w\\.\\-]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}', e):
		print(s)


from re import match as rem
for i in range(int(input())):
	(name, mail) = input().strip().split()
	if rem('^<[a-zA-Z][a-zA-Z0-9\\-._]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>$', mail):
		print(name, mail)


import re
N = int(input())
r = re.compile('^<([a-zA-Z][a-zA-Z0-9\\._-]+)@([a-zA-Z]+)\\.([a-zA-Z]{1,3})>$')
for _ in range(N):
	(name, email) = input().split()
	if r.search(email):
		print(name, email)


import re
import email.utils
n = int(input())
for i in range(n):
	s = input()
	(name, mail) = email.utils.parseaddr(s)
	if re.match('[a-zA-Z][a-zA-Z0-9_\\-\\.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', mail):
		print(email.utils.formataddr((name, mail)))


import re
import sys
EMAIL_REGEX = '^[A-Za-z][A-Za-z0-9\\-\\._]*\\@[A-Za-z]+\\.[A-Za-z]{1,3}$'
N = int(sys.stdin.readline())
for _ in range(N):
	(name, email) = sys.stdin.readline().rstrip().split()
	if re.match(EMAIL_REGEX, email.lstrip('<').rstrip('>')):
		print(name, email)


import re
n = int(input())
emailRegEx = re.compile('^<[a-zA-Z][a-zA-Z0-9\\-\\._]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>$')
for _ in range(n):
	(name, email) = input().split()
	if re.match(emailRegEx, email):
		print(name, email)


import re
for i in range(int(input())):
	s = input()
	if re.search('<[a-zA-Z][\\w\\.-]*@[a-zA-Z]+\\.[A-Za-z]{1,3}>$', s):
		print(s)


import re
n = int(input())
for i in range(0, n):
	lst = input().split()
	name = lst[0]
	email = lst[1]
	if re.search('(^(<[a-zA-Z])(\\w|\\.|-)*@([a-zA-Z]+)\\.([a-zA-Z]{1,3}>)$)', email) != None:
		print(name, email)


import re
n = int(input().strip())
em = re.compile('<([a-z][\\w._-]*)@([a-z]+)[.]([a-z]{1,3})>\\Z')
for i in range(n):
	line = input().strip().split()
	if em.match(line[1]):
		print(line[0], line[1])


import email.utils, re

def validate(data):
	(name, addr) = email.utils.parseaddr(data)
	if re.match('^[a-zA-Z][a-zA-Z0-9_\\-\\.]+@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', addr):
		return email.utils.formataddr((name, addr))
print(*filter(validate, [input().strip() for i in range(int(input()))]), sep='\n')


import re
import email.utils
for _ in range(int(input())):
	S = input()
	if re.search('^[a-z][a-z0-9_\\-\\.]*@[a-z]+\\.[a-z]{1,3}$', email.utils.parseaddr(S)[1], flags=re.I):
		print(S)


import re
regex = re.compile('^[a-z](\\w|\\.|-)+@[a-z]+\\.[a-z]{1,3}$', re.IGNORECASE)
N = int(input())
for idx in range(N):
	(name, email) = input().split()
	if bool(regex.search(email.strip('<>'))) == True:
		print(name, email)


import email.utils
import re
n = int(input())
regex = re.compile('.* <[a-zA-Z][\\w\\-.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>')
for _ in range(n):
	line = input()
	if regex.match(line):
		print(line)


import re
N = int(input())
for _ in range(N):
	tOrg = input().strip()
	e = re.search('<(.*)>', tOrg)
	if e == None:
		continue
	t = e.group(1).strip()
	if re.search('^[a-zA-Z][a-zA-Z0-9\\-._]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', t) != None:
		print(tOrg)


import re
n = int(input())
for i in range(n):
	(name, email) = input().strip().rsplit(' ', maxsplit=1)
	if re.match('^<[a-zA-Z][a-zA-Z0-9-_.]{0,}@[a-zA-Z]+\\.[a-zA-Z]{1,3}>$', email):
		print(name, email)


import re
t = int(input().strip())
for _ in range(t):
	(name, email) = input().strip().split()
	if re.match('<[A-Za-z](\\w|-|\\.|_)+@[A-Za-z]+\\.[A-Za-z]{1,3}>', email):
		print('{} {}'.format(name, email))


import re
n = int(input())
for _ in range(n):
	(name, email) = input().split()
	is_valid_email = re.match('^<[a-z][a-z0-9-\\._]*@[a-z]+\\.[a-z]{1,3}>$', email)
	if is_valid_email:
		print(name, email)


import re
for _ in range(int(input())):
	s = input()
	m = re.search('<[a-z][\\w.-]+@[a-z]+\\.[a-z]{1,3}>', s, re.I)
	if m:
		print(s)


import re
N = int(input())
for i in range(N):
	IN = input()
	(name, email) = IN.split()
	email = email[1:-1]
	if re.fullmatch('[{ALPHA}][\\w\\-\\._]*@[{ALPHA}]*\\.[{ALPHA}]{{1,3}}'.format(ALPHA='abcdefghijklmnopqrstuvwxyz'), email, re.I) != None:
		print(IN)


import re, email.utils
n = int(input())
for t in range(n):
	s = input()
	parsed_email = email.utils.parseaddr(s)[1].strip()
	match_result = bool(re.match('(^[A-Za-z][A-Za-z0-9\\._-]+)@([A-Za-z]+)\\.([A-Za-z]{1,3})$', parsed_email))
	if match_result == True:
		print(s)


from re import match
for i in range(int(input())):
	t = input()
	if match('^<[a-zA-Z][a-zA-Z0-9-_\\.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>$', t.split()[1]):
		print(t)


import email.utils, re
for _ in range(int(input())):
	(name, address) = email.utils.parseaddr(input())
	if re.match('^[A-Za-z][\\w\\d\\.\\-]*@[A-Za-z]+\\.[A-Za-z]{1,3}$', address):
		print(email.utils.formataddr((name, address)))


import re, email.utils
n = int(input())
for _ in range(n):
	inpt = email.utils.parseaddr(input())
	if re.match('^[a-zA-Z][\\w.-]*\\@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', inpt[1]):
		print(email.utils.formataddr(inpt))


import re
import sys
uname = '[A-Za-z][-._A-Za-z0-9]*'
webname = '[A-Za-z]+'
extension = '[A-Za-z]{1,3}'
pat = '^<' + uname + '@' + webname + '\\.' + extension + '>$'
_ = input()
for line in sys.stdin.readlines():
	if re.match(pat, line.split()[-1]):
		print(line.strip())


import re
rem = re.compile('<[a-z][-\\w.]*@[a-z]+\\.[a-z]{1,3}>', re.I)
for lno in range(int(input())):
	(name, email) = input().rstrip('\r').rsplit(' ', 1)
	if rem.fullmatch(email):
		print(name, email)


import re
pat = '^([a-z]+ \\<[a-z][-.\\w]*@[a-z]+\\.[a-z]{1,3}\\>)'
for _ in range(int(input())):
	match = re.match(pat, input(), re.I)
	if match:
		print(match.group(1))


import email.utils
import re
N = int(input())
for i in range(N):
	S = input()
	(realname, email_address) = email.utils.parseaddr(S)
	if re.match('^[a-zA-Z][a-zA-Z0-9\\-\\.\\_]+\\@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', email_address):
		print(email.utils.formataddr((realname, email_address)))


from sys import stdin as inp
import re
N = int(inp.readline().rstrip())
reg = re.compile('<[a-zA-Z][\\w\\-\\.\\_]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>')
for ct in range(N):
	S = inp.readline().rstrip()
	if re.search(reg, S) is not None:
		print(S)


import re
n = int(input().strip())
for i in range(n):
	(name, email) = input().strip().split()
	emailj = email[1:-1]
	res = bool(re.search('^([a-zA-Z][a-zA-Z0-9-_\\.]*)@([a-zA-Z]+)\\.([a-zA-Z]{1,3})$', emailj))
	if res:
		print(name, email)


import re
t = int(input())
for _ in range(t):
	email = input()
	validemail = re.compile('.*?\\<([a-z]+[a-z0-9_\\.\\-]+)@([a-z]+)\\.([a-z]{1,3})\\>.*?')
	mat = validemail.match(email)
	if mat is not None and len(mat.groups()) == 3:
		print(email)


import email.utils
import re
N = int(input())
for _ in range(N):
	s = input()
	e = email.utils.parseaddr(s)[1]
	if re.search('^([a-zA-Z])([0-9a-zA-Z\\-\\_\\.]{0,})(\\@)([a-zA-Z]*)(\\.)([a-zA-Z]{1,3})$', e):
		print(s)


import re
n = int(input())
a = list()
for i in range(n):
	a.append(input())
for b in a:
	if re.search('[a-zA-Z]+ <[a-zA-Z][a-zA-Z0-9-\\._]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>', b):
		print(b)


import re
import email.utils
p = re.compile('^([A-Z]+[A-Z0-9._-]*)@([A-Z]+)\\.([A-Z]{1,3})$', re.IGNORECASE)
for _ in range(int(input())):
	(name, mail) = email.utils.parseaddr(input())
	if (name, mail) != ('', ''):
		if p.match(mail):
			print(email.utils.formataddr((name, mail)))


from email.utils import parseaddr
import re
N = int(input().strip())
for count in range(N):
	email = input().strip()
	match = re.search('.*?\\<([a-z]+[a-z0-9_\\.\\-]+)@([a-z]+)\\.([a-z]{1,3})\\>.*?', email)
	if match:
		print(email)


import re
for i in range(int(input())):
	(name, address) = input().split()
	if re.match('<[a-zA-Z0-9](\\w|\\.|-)*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>', address):
		print(name, address)


import re
import email.utils
for i in range(int(input())):
	match = re.search('^([a-zA-Z][\\da-zA-Z\\.\\-\\_]*) <([a-zA-Z][\\da-zA-Z\\.\\-\\_]*@[a-zA-Z]+\\.[a-zA-Z]{1,3})>$', input().strip())
	if match:
		print(email.utils.formataddr((match.group(1), match.group(2))))


import email.utils, re
for _ in range(int(input())):
	(name, emailaddr) = input().split()
	if re.search('^(<[a-z])([a-z0-9\\.\\-_]{0,})@([a-z]{1,})\\.([a-z]{1,3}>)', emailaddr, re.I):
		print(name, emailaddr)


import email.utils, re
for _ in range(int(input())):
	(name, address) = email.utils.parseaddr(input())
	if re.match('^[a-zA-Z][\\w\\-.]+@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', address) is not None:
		print(name, '<{}>'.format(address))


import re
N = int(input())
List = []
for i in range(0, N):
	List.append(input())
ptrn = '^.+ <[a-zA-Z][-\\._a-zA-Z0-9]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>$'
for j in range(0, N):
	m = re.search(ptrn, List[j])
	if m:
		print(m.group())


import re
for _ in range(int(input())):
	m = re.fullmatch('.* \\<[a-zA-Z][\\w\\.\\-_]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}\\>', input().strip())
	if m != None:
		print(m.group(0))


import email.utils
import re
for _ in range(int(input())):
	(name, address) = email.utils.parseaddr(input())
	if re.search('^[a-zA-Z][\\-\\._a-zA-Z0-9]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', address):
		print(email.utils.formataddr((name, address)))


import re
N = int(input())
for i in range(N):
	(name, email) = input().split()
	re1 = re.match('^\\<[\\w\\-.]+\\@', email)
	re2 = re.match('^\\<[a-zA-Z]', email)
	re3 = re.search('\\@[a-zA-Z]+\\.[a-zA-Z]{1,3}\\>$', email)
	re4 = re.search('\\@{2}|\\.\\.', email)
	if re1 and re2 and re3 and (not re4):
		print('{} {}'.format(name, email))


import re
import email.utils
emailre = re.compile('^' + '[a-zA-Z][a-zA-Z0-9_\\-.]*' + '@' + '[a-zA-Z]+' + '\\.' + '[a-zA-Z]{1,3}' + '$')
for _ in range(int(input())):
	line = input()
	(name, em) = email.utils.parseaddr(line)
	if emailre.match(em):
		print(line)


import re
N = int(input())
for _ in range(N):
	S = input()
	if bool(re.match('^.*?\\s<[A-Za-z][_A-Za-z0-9.-]+@[A-Za-z]+\\.[A-Za-z]{1,3}>$', S)):
		print(S)


import re
for _ in range(int(input().strip())):
	(N, E) = input().strip().split()
	if re.search('^<\\s*[a-zA-Z][a-zA-Z0-9_\\-\\.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}\\s*>$', E, re.I):
		print(N, E)


import re
for _ in range(int(input())):
	a = input().strip()
	if re.match('^.*\\<[a-zA-Z][a-zA-Z0-9\\-\\.\\_]*\\@[a-zA-Z]+\\.[a-zA-Z]{1,3}\\>$', a) != None:
		print(a)


import re
import email.utils
reg = re.compile('(?P<name>\\w+)\\s<(?P<email>[A-Za-z][A-Za-z0-9\\-\\._]*@[A-Za-z]+\\.[a-zA-Z]{1,3})>')
for i in range(int(input())):
	m = reg.search(input())
	if m:
		print(email.utils.formataddr(m.groups(0), m.groups(1)))


import re
for _ in range(int(input())):
	s = input()
	m = re.match('(.*?)\\s*(\\<[a-z][-._a-z0-9]+@[a-z]+\\.[a-z]{1,3}\\>)', s, re.I)
	if m:
		print(' '.join(m.groups()))


import sys
import re

def validate_mail():
	num = int(sys.stdin.readline())
	while num:
		item = sys.stdin.readline()
		(name, mail) = item.split()
		if re.match('^<[a-z]+[a-z0-9._-]*@[a-z]+\\.[a-z]{1,3}>$', mail.lower()):
			sys.stdout.write(item)
		num -= 1
	return

def main():
	validate_mail()
	return
main()


import re
for _ in range(int(input())):
	ip = input()
	if re.search('\\s<([a-zA-Z][\\w.-]{0,})@([a-zA-Z]+)\\.([a-zA-Z]{1,3})>', ip):
		print(ip)


import re

def test(s):
	(name, email) = s.split()
	return bool(re.match('<[A-Za-z][A-Za-z0-9-\\._]*@[A-Za-z]+\\.[A-Za-z]{1,3}>', email))
for _ in range(int(input())):
	s = input()
	if test(s):
		print(s)


import re
N = int(input())
for _ in range(N):
	(name, email) = input().split()
	m = re.match('<([a-zA-Z][0-9a-zA-Z_\\-.]*)@([a-zA-Z]*)\\.([a-zA-Z]{1,3})>', email)
	if m:
		print(name, m.group(0))


import re
N = int(input())
for i in range(N):
	(name, email) = input().split()
	if bool(re.search('^[a-zA-Z][\\w\\-\\.\\_]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', email.strip('<>'))):
		print(name, email)


import re
import email.utils
for i in range(int(input())):
	(name, mail) = email.utils.parseaddr(input())
	if re.fullmatch('^[a-zA-Z][\\w\\._-]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', mail) != None:
		print('{0} <{1}>'.format(name, mail))


import email.utils
import re
n = int(input())
for i in range(n):
	l = email.utils.parseaddr(input())
	if bool(re.match('[a-zA-Z]+[0-9a-zA-Z.\\-_]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', l[1])):
		print(l[0] + ' <' + l[1] + '>')


import re
for line in range(int(input().strip())):
	string = input().strip()
	index = string.find('<')
	if index > 0:
		(name, email) = (string[0:index], string[index:])
		if re.match('<[a-zA-Z]{1}[\\w.-]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>', email):
			print(string)


__author__ = 'sunghyo.jung'
import email.utils
import re
PATTERN = '^[a-zA-Z][a-zA-Z-._0-9]*@[a-zA-Z]*\\.[a-zA-Z]{1,3}$'
for i in range(int(input().strip())):
	s = input().strip()
	emailaddr = email.utils.parseaddr(s)[1]
	if re.match(PATTERN, emailaddr) != None:
		print(email.utils.formataddr(email.utils.parseaddr(s)))


import re
for _ in range(int(input())):
	(name, email) = input().split()
	if re.match('^[a-zA-Z][a-zA-Z0-9_.-]*@[a-zA-Z]+[.][a-zA-Z]{1,3}$', email[1:-1]):
		print(name, email)


import re
for _ in range(int(input())):
	(name, eaddr) = input().split(' ')
	m = re.match('\\<([A-Za-z]+[A-Za-z\\.\\-_0-9]*)@([A-Za-z]+)\\.([A-Za-z]{1,3})\\>', eaddr)
	if bool(m):
		print(name + ' ' + eaddr)


import sys, re, email.utils
lines = int(input().strip())
for i in range(lines):
	email_tuple = email.utils.parseaddr(str(input().strip()))
	if re.match('[A-Za-z][\\w\\-\\.\\_]*?\\@[A-Za-z]+?\\.[A-Za-z]{1,3}$', email_tuple[1]):
		print(email.utils.formataddr(email_tuple))


import re
for i in range(int(input())):
	line = input()
	if bool(re.match('^.*<[a-zA-Z][a-zA-Z0-9\\.\\-_]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>\\s*$', line)):
		print(line)


import re
import email.utils
for _ in range(int(input())):
	e = email.utils.parseaddr(input())
	if bool(re.match('^[a-z][\\w\\-\\.]*@[a-z]+\\.[a-z]{1,3}$', e[1], re.I)):
		print(email.utils.formataddr(e))


import email.utils, re
for i in range(int(input())):
	str = email.utils.parseaddr(input())
	if re.search('^[A-Za-z][\\.\\w\\d-]+@[A-Za-z]+\\.[A-Za-z]{1,3}$', str[1]):
		print(email.utils.formataddr(str))


import re
for _ in range(int(input())):
	(name, addr) = input().split()
	if re.match('^<[a-z][\\w\\-\\.]*@[a-z]+\\.[a-z]{1,3}>$', addr, re.I):
		print(name, addr)


from email.utils import parseaddr, formataddr
import re
vaild_addr = re.compile('[a-zA-Z][\\w\\-.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}$')
n = int(input())
for _ in range(n):
	addr = parseaddr(input())
	if not addr == ('', ''):
		if vaild_addr.match(addr[1]):
			print(formataddr(addr))


import re
r = re.compile('<[A-Za-z][0-9A-Za-z._-]*@[A-Za-z]+\\.[A-Za-z]{1,3}>')
n_tests = int(input())
for _ in range(n_tests):
	s = input()
	if re.search(r, s):
		print(s)


import re
N = int(input())
for i in range(N):
	iStr = input()
	(name, email) = iStr.split()
	if re.match('<[a-zA-Z][-\\w\\.]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>', email):
		print(iStr)


import re
N = int(input())
for _ in range(N):
	(name, email) = input().split(' ')
	m = re.match('<([a-zA-Z])[-\\.\\w]+@[a-zA-Z]+\\.[a-zA-Z]{1,3}>', email)
	if m:
		print(name + ' ' + email)


import re
r_username = re.compile('\\<([a-zA-Z][a-zA-Z0-9._-]*)\\@([a-zA-Z]+)\\.([a-zA-Z]{1,3})\\>$')
for _ in range(int(input())):
	a = input().strip()
	if re.search(r_username, a):
		print(a)


import re
length = input()
for x in range(int(length)):
	i = input()
	r = re.search('(?<=<)([A-Za-z][-\\.\\w]+)@([A-Za-z]+)\\.([A-Za-z]{1,3})(?=>)', i)
	if r:
		print(i)


import string, email.utils
for _ in range(int(input())):
	(u, m) = email.utils.parseaddr(input())
	try:
		(user, webext) = m.split('@')
		(web, ext) = webext.split('.')
		s = set(string.ascii_letters) | set(string.digits) | set('._-')
		assert not bool(set(user) - s)
		assert user[0] in string.ascii_letters
		assert web.isalpha()
		assert ext.isalpha()
		assert len(ext) in [1, 2, 3]
		print(email.utils.formataddr((u, m)))
	except:
		pass


import re
data = [s for s in [input().strip() for i in range(int(input()))] if re.match('^([A-Za-z]+) <[A-Za-z][A-Za-z0-9_.-]+@[A-Za-z]+\\.[A-Za-z]{1,3}>$', s)]
for i in data:
	print(i)


import re
n = int(input())
for i in range(n):
	email = input()
	if re.search('\\w*\\s<[a-zA-Z][\\w\\.-]*@[a-zA-Z]+\\.[a-zA-Z]{1,3}>', email):
		print(email)


import re

def main():
	n = int(input())
	for i in range(n):
		s = input().strip()
		address = s[s.find('<') + 1:-1]
		if re.match('^[a-zA-Z]+?[a-zA-Z-0-9\\-\\._]*?@[a-zA-Z]+?\\.[a-zA-Z]{1,3}$', address):
			print(s)
main()


import re
N = int(input().strip())

def is_valid(emil):
	m = re.search('(?<=\\<)[a-zA-Z][a-zA-Z0-9_.-]*@[a-zA-Z]+[.][a-zA-Z]{1,3}(?=>)', emil)
	if not m:
		return False
	else:
		return True
for i in range(0, N):
	t = input()
	if is_valid(t):
		print(t)


import re
import email.utils
n = int(input().strip())
for i in range(n):
	(name, mail) = email.utils.parseaddr(input().strip())
	res = re.search('^[a-zA-Z][\\w.-]+\\@[a-zA-Z]+\\.[a-zA-Z]{1,3}$', mail)
	if res:
		print(email.utils.formataddr((name, mail)))


import re
for _ in range(0, int(input())):
	ip = list(map(str, input().split()))
	if bool(re.match('^(\\<)([a-zA-Z]{1})([a-zA-Z0-9.\\-_]*)(\\@)([a-zA-Z]+)([\\.])([a-zA-Z]{1,3})(\\>)$', ip[1])):
		print(ip[0], ip[1], sep=' ')


import email.utils
import re
N = int(input())
for _ in range(N):
	(name, email_str) = email.utils.parseaddr(input())
	if re.search('^[a-zA-Z][\\w\\.-]*@[a-zA-Z]*\\.[a-zA-Z]{1,3}$', email_str):
		print(email.utils.formataddr((name, email_str)))


import re
for _ in range(int(input())):
	s = input()
	m = re.match('.*?\\<([a-z]+[a-z0-9_\\.\\-]+)@([a-z]+)\\.([a-z]{1,3})\\>.*?', s)
	if m is not None and len(m.groups()) == 3:
		print(s)


import re
for _ in range(int(input())):
	line = input().strip()
	if re.search('^[a-z][a-z0-9_\\.\\-]*\\s<[a-z][a-z0-9_\\.\\-]*@[a-z]*\\.[a-z]{1,3}>$', line, flags=re.I):
		print(line)


import re
N = int(input())
valid_email = re.compile('^(?P<name>[a-zA-Z]+) (?P<email><[a-zA-Z][\\w\\-.]+@[a-z]+\\.[a-z]{1,3}>)')
for i in range(N):
	valid = valid_email.search(input())
	if valid:
		print('{} {}'.format(valid.group('name'), valid.group('email')))