• + 1 comment

    Condensed down to 2 statements (plus the import):

    from collections import Counter
    
    d = Counter([input().strip() for _ in range(int(input()))])
    print(*[d[input().strip()] for _ in range(int(input()))], sep='\n')