Help me in solving BEAUTYSTR problem

My issue

why are we writing ans*=(freq[i]+1).Why are we adding that 1 with every element of the frequency array?

My code


from collections import Counter
mod = 10 ** 9 + 7
for _ in range(int(input())):
    n = int(input())
    s = input()
    c = Counter(s)
    tot = 0
    ans = 0
    for v in c.values():
        tot += (1 + tot) * v
    print(tot % mod)

Problem Link: Beautiful Strings Practice Coding Problem - CodeChef

@codersouro28 we have to first multiply its frequency with total then take its mod then add its frequency then take mod because first we add new element in every element of string by its frequency of times, then add all string of that particular element that is its frequency.