T = int(input()) from collections import defaultdict d = defaultdict(list) for i in range(T): N = int(input()) d[N].append(i) ans = [0] * T C = 10 ** 7 dat = list(range(C + 1)) era = [0] * (C + 1) tmp = 0 for i in range(2,C + 1): if era[i] == 0: for j in range(i,C + 1,i): era[j] = 1 dat[j] //= i dat[j] *= (i-1) for i in range(2,C + 1): tmp += dat[i] + (i - 1 - dat[i]) * 2 if i in d: for j in d[i]: ans[j] = tmp print(*ans,sep = "\n") #print(dat)