def main(): length = int(input()) st = input() counts = [(0, 0) for i in range(len(st)+1)] found = set() cur = 0 for i in range(len(st)): c = st[i] if c not in found: found.add(c) cur += 1 counts[i+1] = (cur, counts[i][1]) found = set() cur = 0 for i in range(len(st)-1, -1, -1): c = st[i] if c not in found: found.add(c) cur += 1 counts[i] = (counts[i][0], cur) # print(counts) return max([(c[0]+c[1]) for c in counts]) for _ in range(int(input())): print(main())