import sys input = sys.stdin.readline mod=998244353 T=int(input()) for tests in range(T): N=int(input()) E=[[] for i in range(N)] for i in range(N-1): x,y=map(int,input().split()) x-=1 y-=1 E[x].append(y) E[y].append(x) DICT=dict() ANS=0 for i in range(N): Q=[i] DICT[i]=0 L=[] while Q: x=Q.pop() L.append(x) for to in E[x]: if to in DICT: continue DICT[to]=DICT[x]+1 if DICT[to]==3: L.append(to) ANS+=1 else: Q.append(to) #print(L,DICT) for x in L: if x in DICT: del DICT[x] #print(DICT) print(ANS//2)