import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def brute(N): res = 0 for i in range(1,N+1): for j in range(i+1,N+1): if gcd(i,j) == 1: res += 1 return res M = 10**7 mebius = [1] * (M+1) phi = [i for i in range(M+1)] for p in range(2,M+1): if phi[p] == p: for k in range(p,M+1,p): mebius[k] *= -1 if k%(p*p) == 0: mebius[k] = 0 if mebius[p]!=0: for k in range(p,M+1,p): phi[k] += mebius[p] * (k//p) for i in range(1,M+1): phi[i] += phi[i-1] for _ in range(int(input())): N = int(input()) res = N*(N-1) - (phi[N]-1) print(res)