fork(1) download
  1. # your code goes here
  2. import sys
  3. t = input()
  4.  
  5. while t:
  6. t -= 1
  7. n,p = map(int , raw_input().split() )
  8. x = pow(p,n-1,1000000007)
  9. z = 0
  10. for i in range(0,n):
  11. z = z + pow(p,i,1000000007)
  12. z = z% 1000000007;
  13. #z = (1 - pow(p,n) ) / (1-p)
  14. print z%1000000007,x
  15. sys.exit(0)
  16.  
  17.  
Success #stdin #stdout 0.01s 7900KB
stdin
2
3 2
3 2
stdout
7 4
7 4