#K33437. Concatenation Palindrome Pairs

    ID: 25087 Type: Default 1000ms 256MiB

Concatenation Palindrome Pairs

Concatenation Palindrome Pairs

You are given several test cases. In each test case, you are given N strings consisting of lowercase alphabets. Each string can be rearranged arbitrarily. Your task is to determine whether there exists any pair of distinct strings such that, after rearranging the characters in each string as desired, the concatenation of the two strings can be rearranged to form a palindrome.

A string is a palindrome if it reads the same forwards and backwards. Note that the order of characters in the individual strings can be changed arbitrarily before concatenation. In other words, for two strings s and t, you should check if there exists a rearrangement of s and a rearrangement of t such that when they are concatenated (forming s' + t'), the resulting string is a palindrome.

Hint: Instead of considering the exact order of characters, you may focus on the parity of the frequency of each letter. Two strings can form a palindrome upon concatenation if for every letter the sum of its frequencies is even.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
N1
s11
s12
... 
s1N1
N2
s21
s22
... 
s2N2
...
NT
sT1
sT2
... 
sTNT

Here:

  • T is the number of test cases.
  • For each test case, the first line contains an integer N representing the number of strings.
  • The following N lines each contain a non-empty string (or possibly an empty string) made up of lowercase letters.

outputFormat

For each test case, print a single line to standard output (stdout) containing either "YES" if there exists at least one pair of distinct strings meeting the condition, or "NO" otherwise.

## sample
5
3
abc
cba
xyz
3
abcd
efgh
ijkl
2
ab
ba
4
a
bc
d
aba
2


YES

NO YES NO YES

</p>