Help me in solving COUNTN problem

My issue

pls tell my the problem in my code and logic with example

My code

# cook your dish here
def isprime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

for i in range(int(input())):
    k = int(input())
    if isprime(k):
        m = []
        p = 0
        for j in range(2, k+1):
            if isprime(j):
                m.append(j)
        for l in m:
            p += k * l
        print(p)

    else:
        print(k * 2)

Problem Link: Sum of N Practice Coding Problem

let testcase be
k=9;
as n is notprime you will print 18 as ans
but the correct ans is 18+27=45