Bob is travelling from one city to another. In his way, he sees many other cities pass by. What he does instead of learning the full names of the cities, he learns just the first character of the cities. For example, if he passes by "bhopal", he will just remember the 'b'.
Given the list of N cities that come in his way, print "YES" or "NO" depending on if he is able to remember all the cities distinctly or not.
Note: City name consists of small English alphabets only.
Input and Output:
First line contains T, the number of testcases. Each testcase consists of N, the number of cities. Next N lines contain the names of the cities.
For each testcase, print "YES" or "NO" (quotes for clarity).
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 1000
1 ≤ Length of each city name ≤ 10
We need to read input, process each test case. For each test case, given N city names, we take the first character of each name. If all these first characters are distinct (no duplicates), print "YES", else "NO". Constraints: up to 1000 cities per test, T up to 100, length 1-10, lowercase.
We can just read T, loop, for each test read N (int), then read N lines, for each take first char, store in a set, and also check for duplicates. Since we only care about distinctness, we can use a set to add first chars; if at any point we find a char already in the set, we can mark duplicate and break, but careful: city name may be empty? Constraints length >=1, so ok. Alternatively, after reading all, check if set size equals N. But we might need to ignore duplicate names? Actually condition: "he is able to remember all the cities distinctly or not." If two cities have same first character, he cannot distinguish them, so it's NO. Even if city names are identical? But city names are given as they appear, possibly could be same? But problem says list of N cities that come in his way. They could be same city? Typically they are distinct cities? Not specified, but if same city name appears, then first character same, so not distinct. So answer is NO if any duplicate first characters. So using set size vs N works even if same city repeated. However, if two different cities share first character, set size < N. So that works. So for each test case, we can read all names, collect first characters in a list, then compare len(set) to N.
Edge cases: N up to 1000, T up to 100, total names up to 100k, fine.
We need to output "YES" or "NO" for each test case.
def solve():
import sys
data = sys.stdin.read().splitlines()
it = iter(data)
t = int(next(it).strip())
out = []
for _ in range(t):
n = int(next(it).strip())
first_chars = []
for i in range(n):
city = next(it).strip()
first_chars.append(city[0]) # city length >=1
if len(set(first_chars)) == n:
out.append("YES")
else:
out.append("NO")
sys.stdout.write("\n".join(out))
But careful: there might be blank lines? Usually not. Use strip.
Alternatively, we could process while reading.
Complexities trivial.
Thus answer is to produce a code accordingly.
We must output the answer.
Given the platform, we need to provide final answer: the code.
So I'll produce final answer with explanation and code.
```python
import sys
def solve() -> None:
data = sys.stdin.read().splitlines()
it = iter(data)
t = int(next(it).strip())
out_lines = []
code
for _ in range(t):
n = int(next(it).strip())
first_chars = []
for _ in range(n):
city = next(it).strip()
first_chars.append(city[0]) # city name length is at least 1
if len(set(first_chars)) == n:
out_lines.append("YES")
else:
out_lines.append("NO")
sys.stdout.write("\n".join(out_lines))