from itertools import accumulate
import sys
input = sys.stdin.readline

M = 10**7
totient = list(range(M+1))
for i in range(2, M+1):
    if totient[i] == i:
        for j in range(i, M+1, i):
            totient[j] = totient[j] // i * (i-1)
totient = list(accumulate(totient))

T = int(input())
for _ in range(T):
    N = int(input())
    ans = N * (N - 1) - totient[N] + 1
    print(ans)