Feedback for SPCHEF problem

Problem Link: SPCHEF Problem - CodeChef

Feedback

The time constraints are too strict for py.

for _ in range(int(input())):
n, k, m = map(int, input().split())

p = k**n

res =  (p-1)//(k-1)

print(res%m, p%m)

Even this code isnt working