#C10515. Email Address Validator

    ID: 39729 Type: Default 1000ms 256MiB

Email Address Validator

Email Address Validator

You are given a list of email addresses for each test case. Your task is to validate these email addresses according to the following criteria:

  • The email must start with an alphanumeric character ([a-zA-Z0-9]).
  • Following the first character, it may contain alphanumeric characters, underscores (_), hyphens (-), or dots (.), but it must end with an alphanumeric character before the '@' symbol.
  • The domain part (after '@') should consist of labels separated by dots. Each label must contain only alphanumeric characters and at least one dot must be present.

Formally, an email address is valid if it matches the regular expression: \( ^[a-zA-Z0-9](?:[a-zA-Z0-9._-]*[a-zA-Z0-9])?@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)+$ \).

For each test case, output the valid email addresses in the order they appear, separated by a single space. If there are no valid emails in a test case, output "No valid email addresses".

inputFormat

The input begins with an integer T representing the number of test cases. For each test case:

  • The first line contains an integer N denoting the number of email addresses.
  • The next N lines each contain a single email address.

outputFormat

For each test case, print a single line with the valid email addresses separated by a single space. If no email address is valid in a test case, print "No valid email addresses".

## sample
1
1
valid.email@domain.com
valid.email@domain.com

</p>