n=int(eval(input()));a,b,c,p=1,1,n,n-1

for i in range(n-1):

 p+=a-1;a,b,c=b,c,((n-1)**2+p+c)%(10**9+7)

print(c)
n=int(eval(input()))-1;a,b,c,p=1,1,n+1,n

for _ in[0]*n:p+=a-1;a,b,c=b,c,(n*n+p+c)%(10**9+7)

print(c)
n = int(eval(input()))
a, b, c, p = 1, 1, n, n - 1
for i in range(n - 1):
    p += a - 1
    a, b, c = b, c, ((n - 1) ** 2 + p + c) % (10**9 + 7)
print(c)

n = int(eval(input())) - 1
a, b, c, p = 1, 1, n + 1, n
for _ in [0] * n:
    p += a - 1
    a, b, c = b, c, (n * n + p + c) % (10**9 + 7)
print(c)

-n = int(eval(input())) -a, b, c, p = 1, 1, n, n - 1 -for i in range(n - 1): +n = int(eval(input())) - 1 +a, b, c, p = 1, 1, n + 1, n +for _ in [0] * n: -    a, b, c = b, c, ((n - 1) ** 2 + p + c) % (10**9 + 7) +    a, b, c = b, c, (n * n + p + c) % (10**9 + 7)